package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bifang.assistant.common.enums.ExcelTypeEnum;
import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.assistant.common.vo.OrderVO;
import com.bifang.assistant.common.vo.SessionInfo;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.common.util.DesensitizeUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.common.vo.dict.DictVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.*;
import com.bifang.module.base.core.helper.ApiContainer;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.helper.ExcelCommonHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.base.core.integration.ExcelIntegration;
import com.bifang.module.system.core.dao.model.*;
import com.bifang.module.system.core.dao.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.YwApply.CompanyVO;
import com.jwsoft.manager.common.vo.YwApply.EnrollCheckShLqVO;
import com.jwsoft.manager.common.vo.YwApply.LivePlaceVO;
import com.jwsoft.manager.common.vo.YwApply.StudentStatusVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduEnrollmenBrochure.EduEnrollmenBrochureVO;
import com.jwsoft.manager.common.vo.eduFormEnroll.EduConfigNameAliasVO;
import com.jwsoft.manager.common.vo.eduFormEnroll.EduEnrollSchoolChooseHouseVO;
import com.jwsoft.manager.common.vo.eduFormEnroll.EduEnrollSchoolFileVO;
import com.jwsoft.manager.common.vo.eduFormEnrollParams.EduFormEnrollParamsVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouseDetail.EduHouseDetailVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchoolConfig.FormAppQueryVO;
import com.jwsoft.manager.common.vo.eduSchoolConfig.SchoolConfigQueryVO;
import com.jwsoft.manager.common.vo.eduSchoolConfig.SchoolConfigVO;
import com.jwsoft.manager.common.vo.eduSendMessage.EduSendMessageVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityQueryVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduSocialSecurityDetail.EduSocialSecurityDetailVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.*;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.EduStudentEnrollBeforeVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.StudentEnrollChooseSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollReview.EduStudentEnrollReviewVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollVerification.EduMateria;
import com.jwsoft.manager.common.vo.eduStudentEnrollVerification.EduStudentEnrollVerificationVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollWhite.EduStudentEnrollWhiteVO;
import com.jwsoft.manager.common.vo.eduStudentTj.EduStudentTjVO;
import com.jwsoft.manager.common.vo.eduSyncJhApply.EduSyncJhApplyVO;
import com.jwsoft.manager.common.vo.eduSyncJhApprove.EduSyncJhApproveVO;
import com.jwsoft.manager.common.vo.eduSyncJhDelete.EduSyncExistInfo;
import com.jwsoft.manager.common.vo.eduSyncJhDelete.EduSyncJhDeleteQueryVO;
import com.jwsoft.manager.common.vo.eduSyncJhEnroll.EduSyncJhEnrollVO;
import com.jwsoft.manager.common.vo.eduSystemConfig.EduSystemConfigFuncQueryVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.*;
import com.jwsoft.manager.core.util.EduDesensitizeUtil;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 学生注册表业务实现类
 *
 * @author wangtao
 * @since 2022-12-05
 */
@ApiService(funcCode = "eduStudentEnrollJh", title = "金华学生正式报名管理")
@Slf4j
public class EduStudentEnrollJhIntegrationImpl implements EduStudentEnrollJhIntegration {

    @Autowired
    public EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    public EduhStudentEnrollService eduhStudentEnrollService;
    @Autowired
    private OperationCacheIntegration operationCacheIntegration;
    @Autowired
    private EduPushparentsService eduPushparentsService;
    @Autowired
    private EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduStudentEnrollVerificationService eduStudentEnrollVerificationService;
    @Autowired
    private EduStudentEnrollKindergartenService eduStudentEnrollKindergartenService;
    @Autowired
    private DictHelper dictHelper;
    @Autowired
    private EduSchoolTjService eduSchoolTjService;
    @Autowired
    private ApiContainer apiContainer;
    @Autowired
    private EduHouseDetailService eduHouseDetailService;
    @Autowired
    private EduAddressSchoolService eduAddressSchoolService;
    @Autowired
    private EduStudentEnrollBeforeService eduStudentEnrollBeforeService;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    private EduSchoolService eduSchoolService;
    @Autowired
    private EduSchoolConfigService eduSchoolConfigService;
    @Autowired
    private ExcelIntegration excelIntegration;
    @Value("${spring.servlet.multipart.location}")
    private String tempPath;

    @Autowired
    private EduTalentPoolService eduTalentPoolService;
    @Autowired
    private ExcelCommonHelper excelCommonHelper;

    @Autowired
    private RedisHelper redisHelper;
    @Autowired
    private EduStudentEnrollBeforeJhIntegration eduStudentEnrollBeforeJhIntegration;

    @Autowired
    private EduAreaService eduAreaService;
    @Autowired
    private EduStudentEnrollInvalidService eduStudentEnrollInvalidService;

    @Autowired
    private EduStudentEnrollWhiteService eduStudentEnrollWhiteService;

    @Autowired
    private EduHouseholdService eduHouseholdService;

    @Autowired
    private EduhHouseholdService eduhHouseholdService;

    @Autowired
    private EduFormSpecialParamsService eduFormSpecialParamsService;

    @Autowired
    private EduNetsignService eduNetsignService;

    @Autowired
    private EduSocialSecurityService eduSocialSecurityService;

    @Autowired
    private EduSocialSecurityDetailService eduSocialSecurityDetailService;

    @Autowired
    private EduCompanyService eduCompanyService;

    @Autowired
    private EduLivePlaceService eduLivePlaceService;

    @Autowired
    private EduStudentStatusService eduStudentStatusService;
    @Autowired
    public EduStudentEnrollFamilyService eduStudentEnrollFamilyService;
    @Autowired
    private EduHouseService eduHouseService;
    @Autowired
    private EduhHouseService eduhHouseService;

    @Autowired
    private EduStudentEnrollBlacklistService eduStudentEnrollBlacklistService;

    @Autowired
    private EduFormEnrollParamsService eduFormEnrollParamsService;

    @Autowired
    private CommonIntegration commonIntegration;

    @Autowired
    private EduStudentTjService eduStudentTjService;

    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;

    @Autowired
    private EduSyncJhDeleteIntegration syncJhDeleteIntegration;

    @Autowired
    private EduSyncJhDeleteService eduSyncJhDeleteService;

    @Autowired
    private EduSyncJhApplyIntegration applyIntegration;

    @Autowired
    private EduSyncJhApproveIntegration approveIntegration;

    @Autowired
    private EduSyncJhEnrollIntegration enrollIntegration;

    @Autowired
    private EduAppointSchoolService eduAppointSchoolService;

    @Autowired
    private EduSchoolConfigIntegration eduSchoolConfigIntegration;

    @Autowired
    private EduFormEnrollService eduFormEnrollService;

    @Autowired
    private EduFormSpecialService eduFormSpecialService;

    @Autowired
    private PersonInfoService personInfoService;

    @Autowired
    private EduStudentEnrollReviewService eduStudentEnrollReviewService;
    public static final String REDIS_YHDR = "YWMBAPPLY:yhdr:";
    public static final String batchAdmitKey = "YWBATCHADMIT:";
    public static final String stopKey = "YWJSZS:";

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private EduSchoolLrService eduSchoolLrService;

    @Autowired
    private DictIntegration dictIntegration;

    @Autowired
    private EduSchoolBbService eduSchoolBbService;

    @Autowired
    private EduSchoolVacancyService schoolVacancyService;
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private  EduDataTaskDetailService eduDataTaskDetailService;
    @Autowired
    private EduSendMessageService eduSendMessageService;

    @Autowired
    private EduAddressService eduAddressService;

    @Autowired
    public ExcelModelService excelModelService;

    @Autowired
    public ExcelParamService excelParamService;

    @Autowired
    public SysUserService sysUserService;


    @Autowired
    private static final String STUDENT_ENROLL_TABLE = "edu_student_enroll";
    private static final String EDU_HOUSEHOLD = "edu_household";
    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0001", title = "学生正式报名管理分页查询-金华模式", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public PageInfo<EduStudentEnrollVO> getList(EduStudentEnrollQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }

        if (ObjectUtils.isEmpty(vo.getYear())) {
            vo.setYear(eduHelper.thisYear());
        }

        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            String orderBy = "";
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    orderBy = orderBy + ",";
                    if (orderVO.getProperty().equals("registerDate")) {
                        orderBy = orderBy + "a.";
                    } else if (orderVO.getProperty().equals("qysj")) {
                        orderBy = orderBy + "a.";
                    } else {
                        orderBy = orderBy + "a.";
                    }
                    orderBy = orderBy + StrUtil.toUnderlineCase(orderVO.getProperty()) + " " + orderVO.getOrder();
                }
            }
            vo.setOrderBy(orderBy);

        }
        if (BoolEnum.TRUE.getType().equals(vo.getXxllFlag())) {
            vo.setSource("6");
        }

        List<String> areaCodeList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            List<SelectVO> selectVOList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            areaCodeList = selectVOList.stream()
                    .map(SelectVO::getDictKey)
                    .collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaCodeList.contains(sessionAreaCode)) {
                areaCodeList.add(sessionAreaCode);
            }
        } else {
            areaCodeList.add(vo.getAreaCode());
        }
        if (!CollectionUtils.isEmpty(areaCodeList)) {
            vo.setAreaCodeList(areaCodeList);
        } else {
            throw new AppException("必须传入行政区划");
        }
        //如果校验标志不为空，而且是不校验，则设置四个区的行政区划
        if(StringUtils.isNotBlank(vo.getCheckAreaCodeFlag()) && "0".equals(vo.getCheckAreaCodeFlag())){
            vo.setAreaCodeList(Arrays.asList("330700", "330701", "330702", "330703", "330704"));
        }

        PageInfo<EduStudentEnrollVO> pageInfo = new PageInfo<>();
        List<EduStudentEnrollVO> resultList = new ArrayList<>();
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),STUDENT_ENROLL_TABLE);
        if (!queryHistoryFlag){
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduStudentEnrollVO> list = eduStudentEnrollService.getYwApplyListYq(vo);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            pageInfo= new PageInfo<>(list);
            for (EduStudentEnrollVO enrollVO : list) {
                /*
                 * source:6 学校录入报名数据
                 * */
                if (StringUtils.isNotEmpty(enrollVO.getSource())) {
                    if ("6".equals(enrollVO.getSource())) {
                        enrollVO.setFileInfo(enrollVO.getParam20());
                    }
                }
            }
        }else{
            Boolean encryptFlag = eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_ENROLL_TABLE);
            if (encryptFlag){
                eduStudentEnrollService.queryEncrypt(vo);
            }
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduStudentEnrollVO> list = eduhStudentEnrollService.getYwApplyListYq(vo);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            for (EduStudentEnrollVO enrollVO : list) {
                /*
                 * source:6 学校录入报名数据
                 * */
                if (StringUtils.isNotEmpty(enrollVO.getSource())) {
                    if ("6".equals(enrollVO.getSource())) {
                        enrollVO.setFileInfo(enrollVO.getParam20());
                    }
                }
            }
            // 不为空则获取分页结果
            pageInfo= new PageInfo<>(list);
        }
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        resultList = pageInfo.getList();
        dictHelper.valueToName(resultList, Arrays.asList(EduYwEnrollDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getAreaCode, a -> a, (k1, k2) -> k1));
        boolean flag = false;
        Map<String, EduStudentEnroll> map = new HashMap<>();
        //获取报名id
        List<String> enrollIdList = resultList.stream().map(EduStudentEnrollVO::getStudentEnrollId).distinct().collect(Collectors.toList());
        List<String> authStatusList = new ArrayList<>();
        authStatusList.add(AuthStatusEnum.NODO.getType());
        authStatusList.add(AuthStatusEnum.YES.getType());
        QueryWrapper<EduStudentEnrollInvalid> invalidQueryWrapper = new QueryWrapper<>();
        invalidQueryWrapper.lambda()
                .select(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus)
                .in(EduStudentEnrollInvalid::getStudentEnrollId, enrollIdList)
                .in(EduStudentEnrollInvalid::getAuthStatus, authStatusList);
        List<EduStudentEnrollInvalid> invalidList = eduStudentEnrollInvalidService.list(invalidQueryWrapper);
        Map<String, String> collectMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(invalidList)) {
            collectMap = invalidList.stream().collect(Collectors.toMap(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus));
        }
        for (EduStudentEnrollVO studentEnroll : resultList) {
            if ("1".equals(studentEnroll.getEncryptFlag())){
                eduStudentEnrollService.decrypt(studentEnroll);
            }
            EduStudentEnroll enroll = map.get(studentEnroll.getIdcard());
            studentEnroll.setDelStatus(collectMap.get(studentEnroll.getStudentEnrollId()));
            if (StringUtils.isBlank(studentEnroll.getConfigNameAlias())) {
                studentEnroll.setConfigNameAlias(studentEnroll.getConfigName());
            }
            if (!flag && EnrollStatusFormalEnum.dlq.getType().equals(studentEnroll.getEnrollStatus())) {
                flag = true;
                studentEnroll.setFirstFlag(true);
            } else {
                studentEnroll.setFirstFlag(false);
            }
            //设置街道
            if (!ObjectUtils.isEmpty(areaMap.get(studentEnroll.getStreet()))) {
                studentEnroll.setStreetName(areaMap.get(studentEnroll.getStreet()).getAreaName());
            }
            if (StringUtils.isBlank(studentEnroll.getAdmitFlag())) {
                studentEnroll.setAdmitFlag("2");
                studentEnroll.setAdmitFlagName("待录取");
            } else {
                if (BoolEnum.TRUE.getType().equals(studentEnroll.getAdmitFlag())) {
                    studentEnroll.setAdmitFlagName("已录取");
                } else {
                    studentEnroll.setAdmitFlagName("不予录取");
                }
            }
            if (BoolEnum.TRUE.getType().equals(studentEnroll.getSpecialFlag())) {
                studentEnroll.setSpecialFlagName("是");
            } else {
                studentEnroll.setSpecialFlagName("否");
            }
            if (StringUtils.isNotBlank(studentEnroll.getEnrollStatus())) {
                EnrollStatusFormalEnum formalEnum = EnrollStatusFormalEnum.getByType(studentEnroll.getEnrollStatus());
                studentEnroll.setEnrollStatusName(formalEnum == null ? "未知状态" : formalEnum.getName());
            } else {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                studentEnroll.setEnrollStatusName(EnrollStatusFormalEnum.dsh.getName());
            }
        }
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0041", title = "学生报名撤销分页查询-金华模式", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public PageInfo<EduStudentEnrollVO> getQuashList(EduStudentEnrollQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }

        if (ObjectUtils.isEmpty(vo.getYear())) {
            vo.setYear(eduHelper.thisYear());
        }

        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            String orderBy = "";
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    orderBy = orderBy + ",";
                    if (orderVO.getProperty().equals("registerDate")) {
                        orderBy = orderBy + "a.";
                    } else if (orderVO.getProperty().equals("qysj")) {
                        orderBy = orderBy + "a.";
                    } else {
                        orderBy = orderBy + "a.";
                    }
                    orderBy = orderBy + StrUtil.toUnderlineCase(orderVO.getProperty()) + " " + orderVO.getOrder();
                }
            }
            vo.setOrderBy(orderBy);

        }
        if (BoolEnum.TRUE.getType().equals(vo.getXxllFlag())) {
            vo.setSource("6");
        }

        List<String> areaCodeList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            List<SelectVO> selectVOList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            areaCodeList = selectVOList.stream()
                    .map(SelectVO::getDictKey)
                    .collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaCodeList.contains(sessionAreaCode)) {
                areaCodeList.add(sessionAreaCode);
            }
        } else {
            areaCodeList.add(vo.getAreaCode());
        }
        if (!CollectionUtils.isEmpty(areaCodeList)) {
            vo.setAreaCodeList(areaCodeList);
        } else {
            throw new AppException("必须传入行政区划");
        }
        PageInfo<EduStudentEnrollVO> pageInfo = new PageInfo<>();
        List<EduStudentEnrollVO> resultList = new ArrayList<>();
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),STUDENT_ENROLL_TABLE);
        if (!queryHistoryFlag){
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduStudentEnrollVO> list = eduStudentEnrollService.getYwApplyListYqQuash(vo);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            pageInfo= new PageInfo<>(list);
            for (EduStudentEnrollVO enrollVO : list) {
                /*
                 * source:6 学校录入报名数据
                 * */
                if (StringUtils.isNotEmpty(enrollVO.getSource())) {
                    if ("6".equals(enrollVO.getSource())) {
                        enrollVO.setFileInfo(enrollVO.getParam20());
                    }
                }
            }
        }else{
            Boolean encryptFlag = eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_ENROLL_TABLE);
            if (encryptFlag){
                eduStudentEnrollService.queryEncrypt(vo);
            }
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduStudentEnrollVO> list = eduhStudentEnrollService.getYwApplyListYqQuash(vo);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            for (EduStudentEnrollVO enrollVO : list) {
                /*
                 * source:6 学校录入报名数据
                 * */
                if (StringUtils.isNotEmpty(enrollVO.getSource())) {
                    if ("6".equals(enrollVO.getSource())) {
                        enrollVO.setFileInfo(enrollVO.getParam20());
                    }
                }
            }
            // 不为空则获取分页结果
            pageInfo= new PageInfo<>(list);
        }
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        resultList = pageInfo.getList();
        dictHelper.valueToName(resultList, Arrays.asList(EduYwEnrollDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getAreaCode, a -> a, (k1, k2) -> k1));
        boolean flag = false;
        Map<String, EduStudentEnroll> map = new HashMap<>();
        //获取报名id
        List<String> enrollIdList = resultList.stream().map(EduStudentEnrollVO::getStudentEnrollId).distinct().collect(Collectors.toList());
        List<String> authStatusList = new ArrayList<>();
        authStatusList.add(AuthStatusEnum.NODO.getType());
        authStatusList.add(AuthStatusEnum.YES.getType());
        QueryWrapper<EduStudentEnrollInvalid> invalidQueryWrapper = new QueryWrapper<>();
        invalidQueryWrapper.lambda()
                .select(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus)
                .in(EduStudentEnrollInvalid::getStudentEnrollId, enrollIdList)
                .in(EduStudentEnrollInvalid::getAuthStatus, authStatusList);
        List<EduStudentEnrollInvalid> invalidList = eduStudentEnrollInvalidService.list(invalidQueryWrapper);
        Map<String, String> collectMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(invalidList)) {
            collectMap = invalidList.stream().collect(Collectors.toMap(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus));
        }

        // 收集所有不重复的创建用户ID和修改用户ID
        List<String> userIdList = resultList.stream()
                .flatMap(enroll -> Stream.of(enroll.getCreateName(), enroll.getUpdateName()))
                .filter(Objects::nonNull)
                .distinct()
                .collect(Collectors.toList());
        Map<String, String> userMap = new HashMap<>();

        if (!CollectionUtils.isEmpty(userIdList)){
            QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
            userQueryWrapper.lambda()
                    .in(SysUser::getUserId, userIdList);
            List<SysUser> userList = sysUserService.list(userQueryWrapper);
            userMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getFullName));
        }

        for (EduStudentEnrollVO studentEnroll : resultList) {
            if ("1".equals(studentEnroll.getEncryptFlag())){
                eduStudentEnrollService.decrypt(studentEnroll);
            }
            EduStudentEnroll enroll = map.get(studentEnroll.getIdcard());
            studentEnroll.setDelStatus(collectMap.get(studentEnroll.getStudentEnrollId()));
            if (StringUtils.isBlank(studentEnroll.getConfigNameAlias())) {
                studentEnroll.setConfigNameAlias(studentEnroll.getConfigName());
            }
            if (!flag && EnrollStatusFormalEnum.dlq.getType().equals(studentEnroll.getEnrollStatus())) {
                flag = true;
                studentEnroll.setFirstFlag(true);
            } else {
                studentEnroll.setFirstFlag(false);
            }
            //设置街道
            if (!ObjectUtils.isEmpty(areaMap.get(studentEnroll.getStreet()))) {
                studentEnroll.setStreetName(areaMap.get(studentEnroll.getStreet()).getAreaName());
            }
            if (StringUtils.isBlank(studentEnroll.getAdmitFlag())) {
                studentEnroll.setAdmitFlag("2");
                studentEnroll.setAdmitFlagName("待录取");
            } else {
                if (BoolEnum.TRUE.getType().equals(studentEnroll.getAdmitFlag())) {
                    studentEnroll.setAdmitFlagName("已录取");
                } else {
                    studentEnroll.setAdmitFlagName("不予录取");
                }
            }
            if (BoolEnum.TRUE.getType().equals(studentEnroll.getSpecialFlag())) {
                studentEnroll.setSpecialFlagName("是");
            } else {
                studentEnroll.setSpecialFlagName("否");
            }
            if (StringUtils.isNotBlank(studentEnroll.getEnrollStatus())) {
                EnrollStatusFormalEnum formalEnum = EnrollStatusFormalEnum.getByType(studentEnroll.getEnrollStatus());
                studentEnroll.setEnrollStatusName(formalEnum == null ? "未知状态" : formalEnum.getName());
            } else {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                studentEnroll.setEnrollStatusName(EnrollStatusFormalEnum.dsh.getName());
            }

            String createUser = userMap.get(studentEnroll.getCreateName());
            if(createUser != null){
                studentEnroll.setCreateNameChinese(createUser);
            }
            String updateUser = userMap.get(studentEnroll.getUpdateName());
            if(updateUser != null){
                studentEnroll.setUpdateNameChinese(updateUser);
            }
        }
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0040", title = "教育局查询单个学生报名信息-金华模式", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public PageInfo<EduStudentEnrollVO> getListByJyj(EduStudentEnrollQueryVO vo) {
       if (StringUtils.isBlank(vo.getIdcard()) && StringUtils.isBlank(vo.getFullName())
               && StringUtils.isBlank(vo.getFatherIdcard()) && StringUtils.isBlank(vo.getFatherName()) && StringUtils.isBlank(vo.getFatherCellphone())
               && StringUtils.isBlank(vo.getMotherIdcard()) && StringUtils.isBlank(vo.getMotherName()) && StringUtils.isBlank(vo.getMotherCellphone())){
           throw new AppException("至少输入一个需要查询学生的条件!");
        }
       vo.setCheckAreaCodeFlag("0");//不校验行政区划
       return this.getList(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0002", title = "学生正式报名管理根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduStudentEnrollVO getById(EduStudentEnrollKeyVO vo) {
        EduStudentEnroll entity = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("查询不到详细信息!");
        }
        EduStudentEnrollVO result = Convert.convert(EduStudentEnrollVO.class, entity);
        QueryWrapper<EduStudentEnrollVerification> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollVerification::getStudentEnrollId, result.getStudentEnrollId());
        List<EduStudentEnrollVerification> list = eduStudentEnrollVerificationService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            result.setVerificationVOList(Convert.toList(EduStudentEnrollVerificationVO.class, list));
        } else {
            result.setVerificationVOList(new ArrayList<>());
        }
        LambdaQueryWrapper<EduStudentEnrollPre> preLambdaQueryWrapper = new LambdaQueryWrapper<>();
        preLambdaQueryWrapper.select(EduStudentEnrollPre::getStudentEnrollPreId).eq(EduStudentEnrollPre::getIdcard, entity.getIdcard())
                .eq(EduStudentEnrollPre::getYear, entity.getYear());
        EduStudentEnrollPre eduStudentEnrollPre = eduStudentEnrollPreService.getOne(preLambdaQueryWrapper, false);
        if (eduStudentEnrollPre != null) {
            result.setStudentEnrollPreId(eduStudentEnrollPre.getStudentEnrollPreId());
        }
        return result;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0023", title = "家长端查询可报名的人员信息", funcType = FuncTypeEnum.query)
    public List<BmStudentVO> getPreListByToken(BmQueryVO vo) {
        String idcard = SessionUtil.getSessionInfo() != null ? SessionUtil.getSessionInfo().getIdcard() : null;
        if (StringUtils.isBlank(idcard)) {
            throw new AppException("用户未登录或未获取到身份信息");
        }
        int year = eduHelper.thisYear();

        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                        }).eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType());
        if (StringUtils.isNotBlank(vo.getSchoolCategory())) {
            queryWrapper.lambda().eq(EduStudentEnrollPre::getSchoolCategory, vo.getSchoolCategory());
        }
        List<EduStudentEnrollPre> list = eduStudentEnrollPreService.list(queryWrapper);
        List<BmStudentVO> retList = new ArrayList<>();
        boolean flag = true;
        if (!CollectionUtils.isEmpty(list)) {
            Map<String, String> beforeMap = new HashMap<>();
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getSpecialFlag())) {
                List<String> preIdList = list.stream().map(EduStudentEnrollPre::getStudentEnrollPreId).distinct().collect(Collectors.toList());
                QueryWrapper<EduStudentEnrollBefore> beforeQueryWrapper = new QueryWrapper<>();
                beforeQueryWrapper.lambda().select(EduStudentEnrollBefore::getStudentEnrollPreId).eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.TRUE.getType())
                        .in(EduStudentEnrollBefore::getStudentEnrollPreId, preIdList)
                        .eq(EduStudentEnrollBefore::getAuthStatus, AuthStatusEnum.YES.getType());
                List<EduStudentEnrollBefore> beforeList = eduStudentEnrollBeforeService.list(beforeQueryWrapper);
                if (!CollectionUtils.isEmpty(beforeList)) {
                    beforeMap = beforeList.stream().collect(Collectors.toMap(EduStudentEnrollBefore::getStudentEnrollPreId, EduStudentEnrollBefore::getStudentEnrollPreId, (k1, k2) -> k1));
                }
            }
            List<String> enrollStatusList = new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());

            for (EduStudentEnrollPre pre : list) {
                QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().eq(EduStudentEnroll::getIdcard, pre.getIdcard())
                        .eq(EduStudentEnroll::getYear, pre.getYear())
                        .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
                if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
                    BmStudentVO studentEnrollPreVO = Convert.convert(BmStudentVO.class, pre);
                    QueryWrapper<EduStudentEnrollBefore> beforeQueryWrapper = new QueryWrapper<>();
                    beforeQueryWrapper.lambda().eq(EduStudentEnrollBefore::getStudentEnrollPreId, pre.getStudentEnrollPreId())
                            .eq(EduStudentEnrollBefore::getYear, pre.getYear())
                            .eq(EduStudentEnrollBefore::getAuthStatus, AuthStatusEnum.YES.getType());
                    if (eduStudentEnrollBeforeService.count(beforeQueryWrapper) <= 0) {
                        studentEnrollPreVO.setYjbmFlag(false);
                    } else {
                        studentEnrollPreVO.setYjbmFlag(true);
                    }
                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getSpecialFlag())) {
                        //只取特殊通道人员
                        if (beforeMap.containsKey(pre.getStudentEnrollPreId())) {
                            retList.add(studentEnrollPreVO);
                        }
                    } else {
                        retList.add(studentEnrollPreVO);
                    }
                } else {
                    flag = false;
                }
            }
        }

        if (CollectionUtils.isEmpty(retList)) {
            if (!flag) {
                throw new AppException(2, "已报名，是否请前往我的报名查看报名结果？");
            } else {
                throw new AppException(3, "该学段在系统中未匹配到适龄子女，是否前往准新生登记办理登记？");
            }
        }

        return retList;

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0028", title = "家长端查询可报名的人员信息详情", funcType = FuncTypeEnum.query)
    public EduStudentEnrollPreVO getBeforeByPreId(EduStudentEnrollPreKeyVO vo) {
        Integer year = eduHelper.thisYear();
        if(vo.getYear() == null){
            vo.setYear(year);
        }
        String idcard = SessionUtil.getSessionInfo() != null ? SessionUtil.getSessionInfo().getIdcard() : "";
        EduStudentEnrollPreVO enrollPreVO = eduStudentEnrollBeforeJhIntegration.getPreDetail(vo);
        EduStudentEnrollPreVO preVO = new EduStudentEnrollPreVO();
        BeanUtil.copyProperties(enrollPreVO, preVO);
        if (StringUtils.isBlank(preVO.getAreaCode())) {
            preVO.setAreaCode(eduHelper.thisAreaCode());
        }
        if (StringUtils.isBlank(preVO.getFatherCardType())) {
            preVO.setFatherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getMotherCardType())) {
            preVO.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getCardType())) {
            preVO.setCardType(CardTypeEnum.idcard.getType());
        }
        preVO.setSchoolId(null);

        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        if(StringUtils.isBlank(vo.getAreaCode())){
            queryVO.setAreaCode(preVO.getAreaCode());
        }else{
            queryVO.setAreaCode(vo.getAreaCode());
        }
        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        if (eduOperationCacheVO == null) {
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();

        EduOperationCacheDetailVO bmOperation = operation.get("YW002");//第一批
        EduOperationCacheDetailVO bbOperation = operation.get("YW022");//第二批
        EduOperationCacheDetailVO qbOperation = operation.get("YW010");//第三批
        EduOperationCacheDetailVO bmxxOperation = operation.get("YW066");//第一批小学报名业务期
        EduOperationCacheDetailVO bmczOperation = operation.get("YW067");//第一批初中报名业务期
        EduOperationCacheDetailVO bbxxOperation = operation.get("YW068");//第二批小学报名业务期
        EduOperationCacheDetailVO bbczOperation = operation.get("YW069");//第二批初中报名业务期
        EduOperationCacheDetailVO qbxxOperation = operation.get("YW070");//第三批小学报名业务期
        EduOperationCacheDetailVO qbczOperation = operation.get("YW071");//第三批初中报名业务期
        EduOperationCacheDetailVO bbTwoOperation = operation.get("YW072");//第二批第二次
        EduOperationCacheDetailVO bbTwoXxOperation = operation.get("YW073");//第二批小学第二次
        EduOperationCacheDetailVO bbTwoCzOperation = operation.get("YW074");//第二批初中第二次
        //判断是否报名业务期
        boolean bmFlag = bmOperation == null ? false : bmOperation.isFlag();
        boolean bmxxFlag = bmxxOperation == null ? false : bmxxOperation.isFlag();
        boolean bmczFlag = bmczOperation == null ? false : bmczOperation.isFlag();
        //判断是否补报业务期
        boolean bbFlag = bbOperation == null ? false : bbOperation.isFlag();
        boolean bbxxFlag = bbxxOperation == null ? false : bbxxOperation.isFlag();
        boolean bbczFlag = bbczOperation == null ? false : bbczOperation.isFlag();
        //第二批次第二次
        boolean bbTwoFlag = bbTwoOperation == null ? false : bbTwoOperation.isFlag();
        boolean bbxxTwoFlag = bbTwoXxOperation == null ? false : bbTwoXxOperation.isFlag();
        boolean bbczTwoFlag = bbTwoCzOperation == null ? false : bbTwoCzOperation.isFlag();
        //判断是否空额抢报业务期
        boolean qbFlag = qbOperation == null ? false : qbOperation.isFlag();
        boolean qbxxFlag = qbxxOperation == null ? false : qbxxOperation.isFlag();
        boolean qbczFlag = qbczOperation == null ? false : qbczOperation.isFlag();
        CommonVO commonTestVO = new CommonVO();
        commonTestVO.setParamKey("imitate_flag");
        String mnFlagStr = commonIntegration.getValueByKey(commonTestVO);
        preVO.setMnFlag(false);
        if ("1".equalsIgnoreCase(mnFlagStr) || "true".equalsIgnoreCase(mnFlagStr)) {
            //开启模拟报名
            EduOperationCacheDetailVO mnOperation = operation.get("YW062");//模拟报名时间
            //判断是否模拟报名业务期
            boolean mnFlag = mnOperation == null ? false : mnOperation.isFlag();
            if (!mnFlag && !bmFlag && !bbFlag && !qbFlag && !bbTwoFlag) {
                throw new AppException("未在有效报名时间内");
            }
            preVO.setMnFlag(mnFlag);
        } else {
            if (!bmFlag && !bbFlag && !bbTwoFlag && !qbFlag) {
                throw new AppException("未在有效报名时间内");
            }
        }
        CommonVO commonTwoVO = new CommonVO();
        commonTwoVO.setParamKey("BM_DEP_DC");
        String twoFlagStr = commonIntegration.getValueByKey(commonTwoVO);
        if ("1".equalsIgnoreCase(twoFlagStr) || "true".equalsIgnoreCase(twoFlagStr)) {
            preVO.setBbTwoEnable(true);
        }else{
            preVO.setBbTwoEnable(false);
        }
        String schoolCategory = enrollPreVO.getSchoolCategory();
        preVO.setEnrollFlag(false);
        preVO.setBbFlag(false);
        preVO.setBbTwoFlag(false);
        preVO.setQbFlag(false);
        if (bmFlag) {
            if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bmxxFlag) {
                    throw new AppException("未在小学第一批次有效报名时间内");
                } else {
                    preVO.setEnrollFlag(true);
                }
            } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bmczFlag) {
                    throw new AppException("未在初中第一批次有效报名时间内");
                } else {
                    preVO.setEnrollFlag(true);
                }
            }
        }
        if (bbFlag) {
            if (!bbxxTwoFlag&&SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bbxxFlag) {
                    throw new AppException("未在小学第二批次有效报名时间内");
                } else {
                    preVO.setBbFlag(true);
                }
            }
            if (!bbczTwoFlag&&SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bbczFlag) {
                    throw new AppException("未在初中第二批次有效报名时间内");
                } else {
                    preVO.setBbFlag(true);
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolId())) {
                //判断选择的学校是否在第二批次名单内
                QueryWrapper<EduSchoolBb> bbQueryWrapper = new QueryWrapper<>();
                bbQueryWrapper.lambda().eq(EduSchoolBb::getYear, year)
                        .eq(EduSchoolBb::getSchoolId, vo.getSchoolId());
                List<EduSchoolBb> eduSchoolBbList = eduSchoolBbService.list(bbQueryWrapper);
                if (CollectionUtils.isEmpty(eduSchoolBbList)) {
                    throw new AppException("您报名的学校不在第二批学校名单范围内，请选择其他学校报名");
                }
            }
        }
        if (bbTwoFlag) {
            if (!bbxxFlag&&SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bbxxTwoFlag) {
                    throw new AppException("未在小学第二批次第二轮有效报名时间内");
                } else {
                    preVO.setBbTwoFlag(true);
                }
            }
            if (!bbczFlag&&SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                if (!bbczTwoFlag) {
                    throw new AppException("未在初中第二批次第二轮有效报名时间内");
                } else {
                    preVO.setBbTwoFlag(true);
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolId())) {
                //判断选择的学校是否在第二批次名单内
                QueryWrapper<EduSchoolBb> bbQueryWrapper = new QueryWrapper<>();
                bbQueryWrapper.lambda().eq(EduSchoolBb::getYear, year)
                        .eq(EduSchoolBb::getSchoolId, vo.getSchoolId());
                List<EduSchoolBb> eduSchoolBbList = eduSchoolBbService.list(bbQueryWrapper);
                if (CollectionUtils.isEmpty(eduSchoolBbList)) {
                    throw new AppException("您报名的学校不在第二批学校名单范围内，请选择其他学校报名");
                }
            }
        }
        if(bbFlag&&bbTwoFlag){
            if(bbxxFlag&&bbxxTwoFlag){
                throw new  AppException("系统小学报名批次参数设置有误");
            }
            if(bbczFlag&&bbczTwoFlag){
                throw new  AppException("系统初中报名批次参数设置有误");
            }
        }
        if (qbFlag) {
            if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                if (!qbxxFlag) {
                    throw new AppException("未在小学第三批次有效报名时间内");
                } else {
                    preVO.setQbFlag(true);
                }
            } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                if (!qbczFlag) {
                    throw new AppException("未在初中第三批次有效报名时间内");
                } else {
                    preVO.setQbFlag(true);
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolId())) {
                //判断选择的学校是否在第三批次名单内
                QueryWrapper<EduSchoolVacancy> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda().eq(EduSchoolVacancy::getYear, year)
                        .eq(EduSchoolVacancy::getSchoolId, vo.getSchoolId())
                        .gt(EduSchoolVacancy::getVacancyNum, "0");
                long count = schoolVacancyService.count(queryWrapper);
                if (count == 0) {
                    throw new AppException("您报名的学校不在第三批学校名单范围内，请选择其他学校报名！");
                }
            }
        }

        boolean canEnrollFlag = false;
        //处理可报名数据
        if (!CollectionUtils.isEmpty(preVO.getEnrollBeforeList())) {
            if (StringUtils.isNotBlank(vo.getAreaCode())) {
                canEnrollFlag = false;
                List<EduStudentEnrollBeforeVO> beforeVOList = new ArrayList<>();
                for (EduStudentEnrollBeforeVO beforeVO : preVO.getEnrollBeforeList()) {
                    if (vo.getAreaCode().equalsIgnoreCase(beforeVO.getAreaCode())) {
                        beforeVOList.add(beforeVO);
                        canEnrollFlag = true;
                    }

                }
                preVO.setEnrollBeforeList(beforeVOList);
            } else {
                canEnrollFlag = true;
            }

        }
        //处理可报名学校
        if (!CollectionUtils.isEmpty(preVO.getChooseSchoolList())) {
            if (StringUtils.isNotBlank(vo.getAreaCode())) {
                List<StudentEnrollChooseSchoolVO> chooseList = new ArrayList<>();
                for (StudentEnrollChooseSchoolVO chooseSchoolVO : preVO.getChooseSchoolList()) {
                    if (vo.getAreaCode().equalsIgnoreCase(chooseSchoolVO.getAreaCode())) {
                        chooseList.add(chooseSchoolVO);
                    }
                }
                preVO.setChooseSchoolList(chooseList);
            }

        }
        //处理房产数据只保留有效数据
        if (!CollectionUtils.isEmpty(preVO.getHouseList())) {
            List<EduHouseVO> houseVOList = new ArrayList<>();
            Map<String, String> houseMap = new HashMap<>();
            boolean hasHouse = false;
            for (EduHouseVO eduHouseVO : preVO.getHouseList()) {
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduHouseVO.getStatus())) {
                    if (StringUtils.isBlank(eduHouseVO.getPrimarySchoolOne())) {
                        hasHouse = true;
                    } else {
                        Double p = Double.parseDouble(eduHouseVO.getPrimarySchoolOne().replaceAll("%", ""));
                        if (p > 50) {
                            hasHouse = true;
                        }
                    }

                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(preVO.getAgentEnrollFlag())) {
                        //可代理报名
                        if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                            houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                            List<String> gyHouseIdList = new ArrayList<>();
                            gyHouseIdList.add(eduHouseVO.getHouseId());
                            eduHouseVO.setGyHouseIdList(gyHouseIdList);
                            houseVOList.add(eduHouseVO);
                        } else {
                            for (EduHouseVO houseVO : houseVOList) {
                                if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                    List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                    gyHouseIdList.add(eduHouseVO.getHouseId());
                                    eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                    if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                        houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                    }

                                    break;
                                }
                            }
                        }
                    } else {
                        List<EduHouseDetailVO> detailList = eduHouseVO.getDetailList();
                        if (!CollectionUtils.isEmpty(detailList)) {
                            for (EduHouseDetailVO eduHouseDetailVO : detailList) {

                                //只能保留房产所有人的房产信息
                                if (idcard.equalsIgnoreCase(eduHouseDetailVO.getIdcard())) {
                                    if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                                        houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                                        List<String> gyHouseIdList = new ArrayList<>();
                                        gyHouseIdList.add(eduHouseVO.getHouseId());
                                        eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                        houseVOList.add(eduHouseVO);
                                    } else {
                                        for (EduHouseVO houseVO : houseVOList) {
                                            if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                                List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                                gyHouseIdList.add(eduHouseVO.getHouseId());
                                                eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                                if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                                    houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (preVO.getIdcard().equalsIgnoreCase(eduHouseDetailVO.getIdcard())) {
                                    //孩子的房产父母双方都能报名
                                    if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                                        houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                                        List<String> gyHouseIdList = new ArrayList<>();
                                        gyHouseIdList.add(eduHouseVO.getHouseId());
                                        eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                        houseVOList.add(eduHouseVO);
                                    } else {
                                        for (EduHouseVO houseVO : houseVOList) {
                                            if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                                List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                                gyHouseIdList.add(eduHouseVO.getHouseId());
                                                eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                                if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                                    houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }
            preVO.setHouseList(houseVOList);
            preVO.setHasHouse(hasHouse);
            if (!CollectionUtils.isEmpty(houseVOList)) {
                canEnrollFlag = true;
            }
        }
        //处理户籍数据
        if (preVO.getHouseHoldVO() != null) {
            canEnrollFlag = true;
            preVO.setHouseholdId(preVO.getHouseholdId());
            preVO.setHouseholdPlace(preVO.getHouseholdAddress());
        }
        //处理参保数据
        if (!CollectionUtils.isEmpty(preVO.getCbList())) {
            List<EduSocialSecurityVO> cbList = new ArrayList<>();
            for (EduSocialSecurityVO eduSocialSecurityVO : preVO.getCbList()) {
                if ("110".equalsIgnoreCase(eduSocialSecurityVO.getAae140())
                        && "1".equalsIgnoreCase(eduSocialSecurityVO.getStatus())
                        && "1".equalsIgnoreCase(eduSocialSecurityVO.getContinuityFlag())) {
                    cbList.add(eduSocialSecurityVO);
                }
            }
            preVO.setCbList(cbList);
            if (!CollectionUtils.isEmpty(cbList)) {
                canEnrollFlag = true;
            }
        }
        //处理居住证信息
        if (!CollectionUtils.isEmpty(preVO.getJzzList())) {
            EduOperationCacheQueryVO queryOpVO = new EduOperationCacheQueryVO();
            queryOpVO.setOperating("YW051");
            queryOpVO.setAreaCode(preVO.getAreaCode());
            queryOpVO.setClassify("2");
            EduOperationCacheDetailVO jzzOption = eduSystemConfigIntegration.getEduOperationOne(queryOpVO);
            Integer endTime = 0;
            if (jzzOption != null && jzzOption.getEndTime() != null) {
                endTime = Integer.parseInt(DateUtil.format(jzzOption.getEndTime(), "YYYYMMDD"));
            } else {
                endTime = Integer.parseInt(preVO.getYear() + "0630");
            }
            List<EduLivePlaceVO> livePlaceList = new ArrayList<>();
            String today = DateUtil.today().replaceAll("-", "");
            for (EduLivePlaceVO eduLivePlaceVO : preVO.getJzzList()) {

                if (StringUtils.isNotBlank(eduLivePlaceVO.getQzdqrq()) && ("2".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "3".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "5".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "正常".equals(eduLivePlaceVO.getZjzt()))) {
                    //到期时间小于截止的，设置为终止
                    Integer qzdqrq = Integer.parseInt(eduLivePlaceVO.getQzdqrq().replaceAll("-", "").replaceAll("/", ""));
                    if (qzdqrq <= endTime) {
                        if (qzdqrq < Integer.parseInt(today)) {
                            eduLivePlaceVO.setZjztdm("5");
                            eduLivePlaceVO.setZjzt("中止");
                        }
                    } else {
                        eduLivePlaceVO.setZjztdm("2");
                        eduLivePlaceVO.setZjzt("正常");
                        if (StringUtils.isNotBlank(eduLivePlaceVO.getQzrq())) {
                            if (Integer.parseInt(eduLivePlaceVO.getQzrq().replaceAll("-", "").replaceAll("/", "")) > endTime) {
                                eduLivePlaceVO.setZjztdm("5");
                                eduLivePlaceVO.setZjzt("无效");
                            }
                        }

                    }
                } else {
                    if ("正常".equalsIgnoreCase(eduLivePlaceVO.getZjzt())) {
                        eduLivePlaceVO.setZjztdm("2");
                    }
                }

                if ("2".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "正常".equalsIgnoreCase(eduLivePlaceVO.getZjzt())) {
                    livePlaceList.add(eduLivePlaceVO);
                }
            }
            preVO.setJzzList(livePlaceList);
            if (!CollectionUtils.isEmpty(livePlaceList)) {
                canEnrollFlag = true;
            }
        }
        //处理网签信息
        if (!CollectionUtils.isEmpty(preVO.getWqList())) {
            List<EduNetsignVO> wqList = new ArrayList<>();
            for (EduNetsignVO eduNetsignVO : preVO.getWqList()) {
                if (preVO.getAreaCode().equalsIgnoreCase(eduNetsignVO.getAreaCode()) && BoolEnum.TRUE.getType().equalsIgnoreCase(eduNetsignVO.getStatus())) {
                    wqList.add(eduNetsignVO);
                }
            }
            preVO.setWqList(wqList);
            if (!CollectionUtils.isEmpty(wqList)) {
                canEnrollFlag = true;
            }
        }
        preVO.setZsbEnrollFlag(false);

        if (BoolEnum.TRUE.getType().equalsIgnoreCase(preVO.getPrivateAppointFlag())) {
            canEnrollFlag = true;
            EduPrivateAppointStudentVO eduPrivateAppointStudent = preVO.getZsbVO();
            EduStudentEnrollBeforeVO eduStudentEnrollBeforeVO = new EduStudentEnrollBeforeVO();
            eduStudentEnrollBeforeVO.setYear(preVO.getYear());
            eduStudentEnrollBeforeVO.setSchoolId(eduPrivateAppointStudent.getSchoolId());
            EduSchoolVO eduSchoolVO = eduSchoolService.getDetail(eduPrivateAppointStudent.getSchoolId());
            eduStudentEnrollBeforeVO.setSchoolName(eduSchoolVO.getSchoolName());
            eduStudentEnrollBeforeVO.setSchoolCategory(eduSchoolVO.getSchoolCategory());
            eduStudentEnrollBeforeVO.setSchoolNature(eduSchoolVO.getSchoolNature());
            eduStudentEnrollBeforeVO.setConfigName("直升");
            eduStudentEnrollBeforeVO.setPrivateAppointFlag(BoolEnum.TRUE.getType());
            eduStudentEnrollBeforeVO.setStudentEnrollPreId(preVO.getStudentEnrollPreId());
            List<EduStudentEnrollBeforeVO> beforeVOS = new ArrayList<>();
            beforeVOS.add(eduStudentEnrollBeforeVO);
            preVO.setEnrollBeforeList(beforeVOS);
            preVO.setZsbEnrollFlag(true);
        }
        //判断人才
        QueryWrapper<EduTalentPool> talentPoolQueryWrapper = new QueryWrapper<>();
        talentPoolQueryWrapper.lambda().select(EduTalentPool::getTalentId,EduTalentPool::getAreaCode).eq(EduTalentPool::getYear, year);
        if (StringUtils.isNotBlank(preVO.getFatherIdcard())&&StringUtils.isNotBlank(preVO.getMotherIdcard())){
            talentPoolQueryWrapper.lambda().and(wrapper -> wrapper.eq(EduTalentPool::getTalentIdcard, preVO.getFatherIdcard()).or()
                    .eq(EduTalentPool::getTalentIdcard,preVO.getMotherIdcard()));
        }else{
            if (StringUtils.isNotBlank(preVO.getFatherIdcard())){
                talentPoolQueryWrapper.lambda().eq(EduTalentPool::getTalentIdcard, preVO.getFatherIdcard());
            }else if (StringUtils.isNotBlank(preVO.getMotherIdcard())){
                talentPoolQueryWrapper.lambda().eq(EduTalentPool::getTalentIdcard,preVO.getMotherIdcard());
            }
        }
        preVO.setFgFlag(false);
        List<EduTalentPool> eduTalentPoolList = eduTalentPoolService.list(talentPoolQueryWrapper);
        if (!CollectionUtils.isEmpty(eduTalentPoolList)){
            preVO.setFgFlag(true);
            List<String> fgList=new ArrayList<>();
            for (EduTalentPool talentPool:eduTalentPoolList){
                if (StringUtils.isBlank(talentPool.getAreaCode())){
                    fgList=new ArrayList<>();
                    break;
                }else{
                    if (!fgList.contains(talentPool.getAreaCode())){
                        fgList.add(talentPool.getAreaCode());
                    }
                }
            }
            preVO.setFgAreaCodeList(fgList);
        }

        //遇到一方家庭关系比对通过的情况，如果登录方是比对通过一方，则家庭关系设置为比对通过
        if ("2".equalsIgnoreCase(preVO.getFamilyFlag()) || "3".equalsIgnoreCase(preVO.getFamilyFlag())) {
            String loginIdcard = SessionUtil.getSessionInfo() != null ? SessionUtil.getSessionInfo().getIdcard() : "";
            if (StringUtils.isNotBlank(loginIdcard)) {
                if ("2".equalsIgnoreCase(preVO.getFamilyFlag())) {
                    if (StringUtils.isNotBlank(preVO.getFatherIdcard()) && preVO.getFatherIdcard().equalsIgnoreCase(loginIdcard)) {
                        preVO.setFamilyFlag("1");
                    }
                }
                if ("3".equalsIgnoreCase(preVO.getFamilyFlag())) {
                    if (StringUtils.isNotBlank(preVO.getMotherIdcard()) && preVO.getMotherIdcard().equalsIgnoreCase(loginIdcard)) {
                        preVO.setFamilyFlag("1");
                    }
                }
            }
        }

        //处理报名数据
        preVO.setCanEnrollFlag(canEnrollFlag);
        return preVO;
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0081", title = "家长端查询可报名的人员信息-重新提交时查询",
            funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public EduStudentEnrollPreVO getBeforeByPreIdResubmit(EduStudentEnrollPreKeyVO vo) {
        if(vo.getYear()==null){
            vo.setYear(eduHelper.thisYear());
        }
        String idcard = SessionUtil.getSessionInfo() != null ? SessionUtil.getSessionInfo().getIdcard() : "";
        EduStudentEnrollPreVO enrollPreVO = eduStudentEnrollBeforeJhIntegration.getPreDetail(vo);
        EduStudentEnrollPreVO preVO = new EduStudentEnrollPreVO();
        BeanUtil.copyProperties(enrollPreVO, preVO);
        if (StringUtils.isBlank(preVO.getAreaCode())) {
            preVO.setAreaCode(eduHelper.thisAreaCode());
        }
        if (StringUtils.isBlank(preVO.getFatherCardType())) {
            preVO.setFatherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getMotherCardType())) {
            preVO.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getCardType())) {
            preVO.setCardType(CardTypeEnum.idcard.getType());
        }
        preVO.setSchoolId(null);

        boolean canEnrollFlag = false;
        //处理可报名数据
        if (!CollectionUtils.isEmpty(preVO.getEnrollBeforeList())) {
            if (StringUtils.isNotBlank(vo.getAreaCode())) {
                canEnrollFlag = false;
                List<EduStudentEnrollBeforeVO> beforeVOList = new ArrayList<>();
                for (EduStudentEnrollBeforeVO beforeVO : preVO.getEnrollBeforeList()) {
                    if (vo.getAreaCode().equalsIgnoreCase(beforeVO.getAreaCode())) {
                        beforeVOList.add(beforeVO);
                        canEnrollFlag = true;
                    }
                }
                preVO.setEnrollBeforeList(beforeVOList);
            } else {
                canEnrollFlag = true;
            }

        }
        //处理可报名学校
        if (!CollectionUtils.isEmpty(preVO.getChooseSchoolList())) {
            if (StringUtils.isNotBlank(vo.getAreaCode())) {
                List<StudentEnrollChooseSchoolVO> chooseList = new ArrayList<>();
                for (StudentEnrollChooseSchoolVO chooseSchoolVO : preVO.getChooseSchoolList()) {
                    if (vo.getAreaCode().equalsIgnoreCase(chooseSchoolVO.getAreaCode())) {
                        chooseList.add(chooseSchoolVO);
                    }
                }
                preVO.setChooseSchoolList(chooseList);
            }

        }
        //处理房产数据只保留有效数据
        if (!CollectionUtils.isEmpty(preVO.getHouseList())) {
            List<EduHouseVO> houseVOList = new ArrayList<>();
            Map<String, String> houseMap = new HashMap<>();
            boolean hasHouse = false;
            for (EduHouseVO eduHouseVO : preVO.getHouseList()) {
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduHouseVO.getStatus())) {
                    if (StringUtils.isBlank(eduHouseVO.getPrimarySchoolOne())) {
                        hasHouse = true;
                    } else {
                        Double p = Double.parseDouble(eduHouseVO.getPrimarySchoolOne().replaceAll("%", ""));
                        if (p > 50) {
                            hasHouse = true;
                        }
                    }

                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(preVO.getAgentEnrollFlag())) {
                        //可代理报名
                        if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                            houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                            List<String> gyHouseIdList = new ArrayList<>();
                            gyHouseIdList.add(eduHouseVO.getHouseId());
                            eduHouseVO.setGyHouseIdList(gyHouseIdList);
                            houseVOList.add(eduHouseVO);
                        } else {
                            for (EduHouseVO houseVO : houseVOList) {
                                if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                    List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                    gyHouseIdList.add(eduHouseVO.getHouseId());
                                    eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                    if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                        houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                    }

                                    break;
                                }
                            }
                        }
                    } else {
                        List<EduHouseDetailVO> detailList = eduHouseVO.getDetailList();
                        if (!CollectionUtils.isEmpty(detailList)) {
                            for (EduHouseDetailVO eduHouseDetailVO : detailList) {

                                //只能保留房产所有人的房产信息
                                if (idcard.equalsIgnoreCase(eduHouseDetailVO.getIdcard())) {
                                    if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                                        houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                                        List<String> gyHouseIdList = new ArrayList<>();
                                        gyHouseIdList.add(eduHouseVO.getHouseId());
                                        eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                        houseVOList.add(eduHouseVO);
                                    } else {
                                        for (EduHouseVO houseVO : houseVOList) {
                                            if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                                List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                                gyHouseIdList.add(eduHouseVO.getHouseId());
                                                eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                                if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                                    houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (preVO.getIdcard().equalsIgnoreCase(eduHouseDetailVO.getIdcard())) {
                                    //孩子的房产父母双方都能报名
                                    if (!houseMap.containsKey(eduHouseVO.getRealProperty())) {
                                        houseMap.put(eduHouseVO.getRealProperty(), eduHouseVO.getAddress());
                                        List<String> gyHouseIdList = new ArrayList<>();
                                        gyHouseIdList.add(eduHouseVO.getHouseId());
                                        eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                        houseVOList.add(eduHouseVO);
                                    } else {
                                        for (EduHouseVO houseVO : houseVOList) {
                                            if (houseVO.getRealProperty().equalsIgnoreCase(eduHouseVO.getRealProperty())) {
                                                List<String> gyHouseIdList = houseVO.getGyHouseIdList();
                                                gyHouseIdList.add(eduHouseVO.getHouseId());
                                                eduHouseVO.setGyHouseIdList(gyHouseIdList);
                                                if (houseVO.getAddress().indexOf(eduHouseVO.getAddress()) < 0) {
                                                    houseVO.setAddress(houseVO.getAddress() + "," + eduHouseVO.getAddress());
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }
            preVO.setHouseList(houseVOList);
            preVO.setHasHouse(hasHouse);
            if (!CollectionUtils.isEmpty(houseVOList)) {
                canEnrollFlag = true;
            }
        }
        //处理户籍数据
        if (preVO.getHouseHoldVO() != null) {
            canEnrollFlag = true;
            preVO.setHouseholdId(preVO.getHouseholdId());
            preVO.setHouseholdPlace(preVO.getHouseholdAddress());
        }
        //处理参保数据
        if (!CollectionUtils.isEmpty(preVO.getCbList())) {
            List<EduSocialSecurityVO> cbList = new ArrayList<>();
            for (EduSocialSecurityVO eduSocialSecurityVO : preVO.getCbList()) {
                if ("110".equalsIgnoreCase(eduSocialSecurityVO.getAae140())
                        && "1".equalsIgnoreCase(eduSocialSecurityVO.getStatus())
                        && "1".equalsIgnoreCase(eduSocialSecurityVO.getContinuityFlag())) {
                    cbList.add(eduSocialSecurityVO);
                }
            }
            preVO.setCbList(cbList);
            if (!CollectionUtils.isEmpty(cbList)) {
                canEnrollFlag = true;
            }
        }
        //处理居住证信息
        if (!CollectionUtils.isEmpty(preVO.getJzzList())) {
            EduOperationCacheQueryVO queryOpVO = new EduOperationCacheQueryVO();
            queryOpVO.setOperating("YW051");
            queryOpVO.setAreaCode(preVO.getAreaCode());
            queryOpVO.setClassify("2");
            EduOperationCacheDetailVO jzzOption = eduSystemConfigIntegration.getEduOperationOne(queryOpVO);
            Integer endTime = 0;
            if (jzzOption != null && jzzOption.getEndTime() != null) {
                endTime = Integer.parseInt(DateUtil.format(jzzOption.getEndTime(), "YYYYMMDD"));
            } else {
                endTime = Integer.parseInt(preVO.getYear() + "0630");
            }
            List<EduLivePlaceVO> livePlaceList = new ArrayList<>();
            String today = DateUtil.today().replaceAll("-", "");
            for (EduLivePlaceVO eduLivePlaceVO : preVO.getJzzList()) {

                if (StringUtils.isNotBlank(eduLivePlaceVO.getQzdqrq()) && ("2".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "3".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) || "5".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()))) {
                    //到期时间小于截止的，设置为终止
                    Integer qzdqrq = Integer.parseInt(eduLivePlaceVO.getQzdqrq().replaceAll("-", "").replaceAll("/", ""));
                    if (qzdqrq <= endTime) {
                        if (qzdqrq < Integer.parseInt(today)) {
                            eduLivePlaceVO.setZjztdm("5");
                            eduLivePlaceVO.setZjzt("中止");
                        }
                    } else {
                        eduLivePlaceVO.setZjztdm("2");
                        eduLivePlaceVO.setZjzt("正常");
                        if (StringUtils.isNotBlank(eduLivePlaceVO.getQzrq())) {
                            if (Integer.parseInt(eduLivePlaceVO.getQzrq().replaceAll("-", "").replaceAll("/", "")) > endTime) {
                                eduLivePlaceVO.setZjztdm("5");
                                eduLivePlaceVO.setZjzt("无效");
                            }
                        }

                    }
                }

                if ("2".equalsIgnoreCase(eduLivePlaceVO.getZjztdm())) {
                    livePlaceList.add(eduLivePlaceVO);
                }
            }
            preVO.setJzzList(livePlaceList);
            if (!CollectionUtils.isEmpty(livePlaceList)) {
                canEnrollFlag = true;
            }
        }
        //处理网签信息
        if (!CollectionUtils.isEmpty(preVO.getWqList())) {
            List<EduNetsignVO> wqList = new ArrayList<>();
            for (EduNetsignVO eduNetsignVO : preVO.getWqList()) {
                if (preVO.getAreaCode().equalsIgnoreCase(eduNetsignVO.getAreaCode()) && BoolEnum.TRUE.getType().equalsIgnoreCase(eduNetsignVO.getStatus())) {
                    wqList.add(eduNetsignVO);
                }
            }
            preVO.setWqList(wqList);
            if (!CollectionUtils.isEmpty(wqList)) {
                canEnrollFlag = true;
            }
        }
        preVO.setZsbEnrollFlag(false);

        if (BoolEnum.TRUE.getType().equalsIgnoreCase(preVO.getPrivateAppointFlag())) {
            canEnrollFlag = true;
            EduPrivateAppointStudentVO eduPrivateAppointStudent = preVO.getZsbVO();
            EduStudentEnrollBeforeVO eduStudentEnrollBeforeVO = new EduStudentEnrollBeforeVO();
            eduStudentEnrollBeforeVO.setYear(preVO.getYear());
            eduStudentEnrollBeforeVO.setSchoolId(eduPrivateAppointStudent.getSchoolId());
            EduSchoolVO eduSchoolVO = eduSchoolService.getDetail(eduPrivateAppointStudent.getSchoolId());
            eduStudentEnrollBeforeVO.setSchoolName(eduSchoolVO.getSchoolName());
            eduStudentEnrollBeforeVO.setSchoolCategory(eduSchoolVO.getSchoolCategory());
            eduStudentEnrollBeforeVO.setSchoolNature(eduSchoolVO.getSchoolNature());
            eduStudentEnrollBeforeVO.setConfigName("直升");
            eduStudentEnrollBeforeVO.setPrivateAppointFlag(BoolEnum.TRUE.getType());
            eduStudentEnrollBeforeVO.setStudentEnrollPreId(preVO.getStudentEnrollPreId());
            List<EduStudentEnrollBeforeVO> beforeVOS = new ArrayList<>();
            beforeVOS.add(eduStudentEnrollBeforeVO);
            preVO.setEnrollBeforeList(beforeVOS);
            preVO.setZsbEnrollFlag(true);
        }
        //遇到一方家庭关系比对通过的情况，如果登录方是比对通过一方，则家庭关系设置为比对通过
        if ("2".equalsIgnoreCase(preVO.getFamilyFlag()) || "3".equalsIgnoreCase(preVO.getFamilyFlag())) {
            String loginIdcard = SessionUtil.getSessionInfo() != null ? SessionUtil.getSessionInfo().getIdcard() : "";
            if (StringUtils.isNotBlank(loginIdcard)) {
                if ("2".equalsIgnoreCase(preVO.getFamilyFlag())) {
                    if (StringUtils.isNotBlank(preVO.getFatherIdcard()) && preVO.getFatherIdcard().equalsIgnoreCase(loginIdcard)) {
                        preVO.setFamilyFlag("1");
                    }
                }
                if ("3".equalsIgnoreCase(preVO.getFamilyFlag())) {
                    if (StringUtils.isNotBlank(preVO.getMotherIdcard()) && preVO.getMotherIdcard().equalsIgnoreCase(loginIdcard)) {
                        preVO.setFamilyFlag("1");
                    }
                }
            }
        }

        //处理报名数据
        preVO.setCanEnrollFlag(canEnrollFlag);
        return preVO;
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0059", title = "家长端查询可报名的人员信息批量", funcType = FuncTypeEnum.query)
    public List<EduStudentEnrollPreVO> getBeforeBatch(BmQueryVO vo) {
        List<BmStudentVO> bmStudentVOList = getPreListByToken(vo);
        List<EduStudentEnrollPreVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(bmStudentVOList)) {
            return list;
        }
        for (BmStudentVO bmStudentVO : bmStudentVOList) {
            EduStudentEnrollPreKeyVO keyVO = new EduStudentEnrollPreKeyVO();
            keyVO.setStudentEnrollPreId(bmStudentVO.getStudentEnrollPreId());
            keyVO.setAccessToken(vo.getAccessToken());
            EduStudentEnrollPreVO preVO = getBeforeByPreId(keyVO);
            list.add(preVO);

        }
        return list;
    }

    /**
     * 保存前统一校验
     */
    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0003", title = "学生正式报名管理保存前校验", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void checkSave(SaveStudentEnrollVO vo) {


    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0004", title = "学生正式报名管理线下录入报名", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0004",
            operationName = "学生正式报名管理线下录入报名",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public SaveStudentEnrollVO add(SaveStudentEnrollVO vo) {
        vo.setLrFlag(true);
        return saveEnroll(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0084", title = "线下录入导入模板下载", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void downloadModel(ExcelVO vo, HttpServletResponse response) {
        Map<String, List<SelectVO>> dictMap = new HashMap<>();
        String areaCode = SessionUtil.getAreaCode();
        if (areaCode.equalsIgnoreCase("330700")){
            dictMap.put("schoolName", getSchoolDictMap(null));
        }else{
            dictMap.put("schoolName", getSchoolDictMap(areaCode));
        }
        vo.setDictMap(dictMap);
        excelIntegration.downloadModel(vo, response);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0085", title = "线下录入excel导入保存", funcType = FuncTypeEnum.insert)
    public ExcelReadVO readExcel(ExcelVO vo, MultipartFile file) {
        ExcelReadVO excelReadVO = new ExcelReadVO();
        excelReadVO.setCount(0);
        ExcelModelVO excelModelVO = this.getModel(vo);
        InputStream in = null;
        try {
            in = file.getInputStream();
            List<Map<String, Object>> list = excelCommonHelper.readExcel(excelModelVO, in, true);
            List<Map<String, Object>> successList = new ArrayList<>();
            List<Map<String, Object>> errorList = new ArrayList<>();
            //查询学校
            QueryWrapper<EduSchool> schoolQueryWrapper = new QueryWrapper<>();
            schoolQueryWrapper.lambda().ne(EduSchool::getSchoolCategory, SchoolCategoryEnum.KINDERGARTEN.getType());
            List<EduSchool> schoolList = eduSchoolService.list(schoolQueryWrapper);
            for (Map<String, Object> map : list) {
                SaveStudentEnrollVO saveStudentEnrollVO = JSON.parseObject(JSON.toJSONString(map), SaveStudentEnrollVO.class);
                String remarks = "";
                boolean flag = false;

                if (ObjectUtils.isEmpty(saveStudentEnrollVO.getSchoolName())) {
                    remarks += "学校名称不能为空！";
                    flag = true;
                }else {
                    AtomicBoolean schoolFlag = new AtomicBoolean(false);
                    schoolList.forEach(
                            school -> {
                                if (!ObjectUtils.isEmpty(saveStudentEnrollVO.getSchoolName())
                                        && school.getShortName()
                                        .replaceAll("（", "(")
                                        .replaceAll("）", ")")
                                        .equals(
                                                saveStudentEnrollVO.getSchoolName()
                                                        .replaceAll("（", "(")
                                                        .replaceAll("）", ")"))) {
                                    schoolFlag.set(true);
                                    saveStudentEnrollVO.setSchoolId(school.getOrgId());
                                    saveStudentEnrollVO.setSchoolName(school.getSchoolName());
                                    saveStudentEnrollVO.setSchoolNature(school.getSchoolNature());
                                }
                            });
                    if (!schoolFlag.get()) {
                        remarks += "找不到学校信息！";
                        flag = true;
                    }
                }

                if (StringUtils.isBlank(saveStudentEnrollVO.getSchoolNature())){
                    remarks += "没有找到学校类别！";
                    flag = true;
                }else {
                    if(saveStudentEnrollVO.getSchoolNature().equals("0")){
                        saveStudentEnrollVO.setConfigTypeName("公办");
                    }else if(saveStudentEnrollVO.getSchoolNature().equals("1")){
                        saveStudentEnrollVO.setConfigTypeName("民办");
                    }else if(saveStudentEnrollVO.getSchoolNature().equals("2")){
                        saveStudentEnrollVO.setConfigTypeName("民转公");
                    }
                }

                if (ObjectUtils.isEmpty(saveStudentEnrollVO.getConfigName())){
                    remarks += "报名类别不能为空！";
                    flag = true;
                }
                //批量保存
                try {
                    saveStudentEnrollVO.setManagerFlag(true);
                    //如果没有在以下类别里面，设置为特殊通道
                    ArrayList<String> configNameAliasList = new ArrayList<>();
                    configNameAliasList.add(ConfigNameAliasEnum.yzm.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.fwqyzm.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.fwq.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.zxq.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.yhwf.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.yfwh.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.tshk.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.sb.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.jzz.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.fc.getName());
                    configNameAliasList.add(ConfigNameAliasEnum.hj.getName());
                    if (!configNameAliasList.contains(saveStudentEnrollVO.getConfigName())){
                        saveStudentEnrollVO.setSpecialFlag("1");
                    }
                    this.add(saveStudentEnrollVO);
                }catch (AppException appException){
                    remarks += appException.getMessage();
                    flag = true;
                    log.error("excel导入异常",appException);
                }catch (Exception e) {
                    remarks += e.getMessage();
                    flag = true;
                    log.error("excel导入异常",e);
                }

                if (flag) {
                    saveStudentEnrollVO.setExcelRemarks(remarks);
                    errorList.add(JSON.parseObject(JSON.toJSONString(saveStudentEnrollVO), Map.class));
                } else {
                    successList.add(JSON.parseObject(JSON.toJSONString(saveStudentEnrollVO), Map.class));
                }
            }
            excelReadVO.setCount(successList.size() + errorList.size());
            excelReadVO.setSuccessCount(successList.size());
            excelReadVO.setSuccessList(successList);
            excelReadVO.setErrorList(errorList);
            excelReadVO.setErrorCount(errorList.size());
        } catch (AppException appEx) {
            throw appEx;
        } catch (IOException e) {
            throw new AppException("读取文件异常:" + e.getMessage());
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return excelReadVO;
    }

    private List<SelectVO> getSchoolDictMap(String areaCode) {
        LambdaQueryWrapper<EduSchool> queryWrapper = new QueryWrapper<EduSchool>()
                .lambda()
                .select(EduSchool::getOrgId, EduSchool::getShortName)
                .eq(EduSchool::getRecruitStatus, "0")
                .eq(StringUtils.isNotBlank(areaCode),EduSchool::getAreaCode, areaCode)
                .ne(EduSchool::getSchoolCategory, SchoolCategoryEnum.KINDERGARTEN.getType());
        List<EduSchool> schoolList = eduSchoolService.list(queryWrapper);
        List<SelectVO> schoolDictList = new ArrayList<>();
        schoolList.forEach(
                item -> {
                    SelectVO selectVO = new SelectVO();
                    selectVO.setDictKey(item.getOrgId());
                    selectVO.setDictValue(item.getShortName());
                    selectVO.setDictField("schoolName");
                    selectVO.setFieldName("学校");
                    schoolDictList.add(selectVO);
                });
        return schoolDictList;
    }

    public ExcelModelVO getModel(ExcelVO vo) {
        return this.getModel(vo.getModelCode(), vo.getExcelVersion(), vo.getDictMap());
    }

    public ExcelModelVO getModel(
            String modelCode, String version, Map<String, List<SelectVO>> dictMap) {
        if (StringUtils.isBlank(modelCode)) {
            throw new AppException("模板编号不能为空");
        }
        QueryWrapper<ExcelModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExcelModel::getModelCode, modelCode);
        if (StringUtils.isBlank(version)) {
            queryWrapper.lambda().eq(ExcelModel::getNewFlag, BoolEnum.TRUE.getType());
        } else {
            queryWrapper.lambda().eq(ExcelModel::getExcelVersion, version);
        }
        ExcelModel excelModel = excelModelService.getOne(queryWrapper, false);
        if (excelModel == null) {
            throw new AppException("未找到excel模板信息");
        }
        ExcelModelVO excelModelVO = Convert.convert(ExcelModelVO.class, excelModel);
        // 获取字段信息
        List<ExcelParamVO> paramVOList = this.getByModelId(excelModelVO.getId());
        for (ExcelParamVO excelParamVO : paramVOList) {
            if (excelParamVO.getHeaderBgColor() == null) {
                excelParamVO.setHeaderBgColor(excelModelVO.getHeaderBgColor());
            }
            if (excelParamVO.getHeaderColor() == null) {
                excelParamVO.setHeaderColor(excelModelVO.getHeaderColor());
            }
            if (excelParamVO.getBodyBgColor() == null) {
                excelParamVO.setBodyBgColor(excelModelVO.getBodyBgColor());
            }
            if (excelParamVO.getBodyColor() == null) {
                excelParamVO.setBodyColor(excelModelVO.getBodyColor());
            }
            if (StringUtils.isBlank(excelParamVO.getWrapText())) {
                excelParamVO.setWrapText(excelModelVO.getWrapText());
            }
            if (StringUtils.isBlank(excelParamVO.getFontName())) {
                excelParamVO.setFontName(excelModelVO.getFontName());
            }
            if (excelParamVO.getFontSize() == null) {
                excelParamVO.setFontSize(excelModelVO.getFontSize());
            }
            if (excelParamVO.getBorderSize() == null) {
                excelParamVO.setBorderSize(excelModelVO.getBorderSize());
            }
            if (excelParamVO.getBorderColor() == null) {
                excelParamVO.setBorderColor(excelModelVO.getBorderColor());
            }
            if (ExcelFieldVO.CellTypeEnum.SELECT.getType().equals(excelParamVO.getCellType())
                    || ExcelFieldVO.CellTypeEnum.MULTIPLESELECT
                    .getType()
                    .equals(excelParamVO.getCellType())) {
                String dictField = excelParamVO.getDictField();
                if (StringUtils.isBlank(dictField)) {
                    dictField = excelParamVO.getKey();
                }
                if (dictMap != null && dictMap.containsKey(dictField)) {
                    excelParamVO.setCodeList(dictMap.get(dictField));
                } else {
                    List<SelectVO> selectList = sysDictService.getDictByDictField(dictField);
                    excelParamVO.setCodeList(selectList);
                }
            }
        }
        excelModelVO.setParamVOList(paramVOList);
        if (StringUtils.isBlank(excelModelVO.getExcelType())) {
            excelModelVO.setExcelType(ExcelTypeEnum.xls.toString());
        }
        if (StringUtils.isBlank(excelModelVO.getExcelMode())) {
            excelModelVO.setExcelMode("2");
        }
        return excelModelVO;
    }

    public List<ExcelParamVO> getByModelId(String excelModelId) {
        QueryWrapper<ExcelParam> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(ExcelParam::getExcelModelId, excelModelId)
                .orderByAsc(ExcelParam::getOrderNo)
                .orderByAsc(ExcelParam::getCreateTime);
        List<ExcelParam> list = excelParamService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<ExcelParamVO> voList = Convert.toList(ExcelParamVO.class, list);
        return voList;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0019", title = "app端家长报名保存", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0019",
            operationName = "app端家长报名保存",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public SaveStudentEnrollVO saveEnrollApp(SaveStudentEnrollVO vo) {
        vo.setLrFlag(false);
        return saveEnroll(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0076", title = "app端家长报名重新提交材料", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0076",
            operationName = "app端家长报名重新提交材料",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void resubmitEnrollApp(ResubmitStudentEnrollVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (eduStudentEnroll == null) {
            throw new AppException("报名信息不存在");
        }
        if (!EnrollStatusFormalEnum.bh.getType().equals(eduStudentEnroll.getEnrollStatus())) {
            throw new AppException("请联系学校驳回后再操作");
        }
        if (StringUtils.isNotBlank(vo.getHouseId())) {
            if (!vo.getHouseId().equals(eduStudentEnroll.getHouseId())) {
                //获取学校信息
                EduSchoolVO eduSchool = eduSchoolService.getDetail(eduStudentEnroll.getSchoolId());
                boolean allAreaFlag = false;
                EduEnrollmenBrochureVO eduEnrollmenBrochureVO = null;
                if (eduSchool != null) {
                    eduEnrollmenBrochureVO = eduSchool.getEduEnrollmenBrochureVO();
                    if (eduEnrollmenBrochureVO != null && BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getAllAreaFlag())) {
                        allAreaFlag = true;
                    }
                }
                if (eduEnrollmenBrochureVO == null) {
                    throw new AppException("学校招生方案不存在");
                }

                List<String> idcardList = new ArrayList<>();
                if (StringUtils.isNotBlank(eduStudentEnroll.getIdcard())) {
                    idcardList.add(eduStudentEnroll.getIdcard());
                }
                if (StringUtils.isNotBlank(eduStudentEnroll.getFatherIdcard())) {
                    idcardList.add(eduStudentEnroll.getFatherIdcard());
                }
                if (StringUtils.isNotBlank(eduStudentEnroll.getMotherIdcard())) {
                    idcardList.add(eduStudentEnroll.getMotherIdcard());
                }

                List<EduHouse> houseList = eduHouseService.getHouseByAllIdcard(idcardList, eduStudentEnroll.getYear(), "1", null);
                if (!CollectionUtils.isEmpty(houseList)) {
                    List<EduHouseVO> houseVOList = Convert.toList(EduHouseVO.class, houseList);
                    EduHouseVO eduHouse = null;
                    if (!allAreaFlag) {
                        if (CollectionUtils.isEmpty(houseVOList)) {
                            throw new AppException("未匹配到您名下的房产信息，请使用房产所有者的浙里办账号登录报名。如果匹配信息有误，请联系学校");
                        }

                        for (EduHouseVO eduHouseVO : houseVOList) {
                            if (eduHouseVO.getHouseId().equalsIgnoreCase(vo.getHouseId())) {
                                eduHouse = eduHouseVO;
                                break;
                            } else {
                                if (!CollectionUtils.isEmpty(eduHouseVO.getGyHouseIdList())) {
                                    if (eduHouseVO.getGyHouseIdList().contains(vo.getHouseId())) {
                                        eduHouse = eduHouseVO;
                                        break;
                                    }
                                }
                            }
                        }
                        if (eduHouse == null || !BoolEnum.TRUE.getType().equals(eduHouse.getStatus())) {
                            throw new AppException("不是有效的房产");
                        }
                    }
                    if (eduHouse != null && !CollectionUtils.isEmpty(eduHouse.getAreaCodeList())) {
                        if (StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())) {
                            List<String> areaList = Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                            if (StringUtils.isNotBlank(eduSchool.getAreaCode()) && !areaList.contains(eduSchool.getAreaCode())) {
                                areaList.add(eduSchool.getAreaCode());
                            }
                            boolean areaFlag = true;
                            for (String area : areaList) {
                                if (eduHouse.getAreaCodeList().contains(area)) {
                                    areaFlag = false;
                                    break;
                                }
                            }
                            if (areaFlag) {
                                if (!allAreaFlag) {
                                    if (SchoolNatureEnum.mzg.getType().equalsIgnoreCase(eduSchool.getSchoolNature()) || SchoolNatureEnum.mb.getType().equalsIgnoreCase(eduSchool.getSchoolNature())) {
                                        //民办民转公按街道划分
                                        if (!CollectionUtils.isEmpty(eduHouse.getSheetAreaCode())) {
                                            boolean areaSheetFlag = true;
                                            for (String area : areaList) {
                                                if (eduHouse.getSheetAreaCode().contains(area)) {
                                                    areaSheetFlag = false;
                                                    break;
                                                }
                                            }
                                            if (areaSheetFlag) {
                                                throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                            }
                                        } else {
                                            throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                        }

                                    } else {
                                        throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                    }

                                }
                            }
                        } else {
                            if (!eduHouse.getAreaCodeList().contains(eduSchool.getAreaCode())) {
                                if (!allAreaFlag) {
                                    if (SchoolNatureEnum.mzg.getType().equalsIgnoreCase(eduSchool.getSchoolNature()) || SchoolNatureEnum.mb.getType().equalsIgnoreCase(eduSchool.getSchoolNature())) {
                                        //民办民转公按街道划分
                                        if (!CollectionUtils.isEmpty(eduHouse.getSheetAreaCode())) {
                                            if (eduHouse.getSheetAreaCode().contains(eduSchool.getAreaCode())) {
                                                throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                            }
                                        } else {
                                            throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                        }

                                    } else {
                                        throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                    }
                                }
                            }
                        }

                    }

                    if (eduHouse != null) {

                        eduStudentEnroll.setRealProperty(eduHouse.getRealProperty());
                        eduStudentEnroll.setRealPropertyNum(eduHouse.getRealPropertyNum());
                        eduStudentEnroll.setRegisterDate(eduHouse.getRegisterDate());
                        eduStudentEnroll.setQlrName(eduHouse.getQlrName());
                        eduStudentEnroll.setHouseAdreess(eduHouse.getAddress());
                        //判断是否只能房产所有者才能报名
                        CommonVO commonVO = new CommonVO();
                        commonVO.setParamKey("only_my_house_enroll");
                        String onlyflag = commonIntegration.getValueByKey(commonVO);
                        boolean canEnroll = false;
                        if ("0".equalsIgnoreCase(onlyflag) || "false".equalsIgnoreCase(onlyflag)) {
                            canEnroll = true;
                        } else {
                            QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                            detailQueryWrapper.lambda().select(EduHouseDetail::getIdcard, EduHouseDetail::getFullName, EduHouseDetail::getHouseId, EduHouseDetail::getRealProperty, EduHouseDetail::getStatus).eq(EduHouseDetail::getHouseId, eduHouse.getHouseId());
                            List<EduHouseDetail> detailVOList = eduHouseDetailService.list(detailQueryWrapper);
                            SessionInfo sessionInfo = SessionUtil.getSessionInfo();
                            if (sessionInfo == null) {
                                throw new AppException("请先登录后再操作");
                            }
                            if (!CollectionUtils.isEmpty(detailVOList)) {
                                for (EduHouseDetail detailVO : detailVOList) {
                                    if (StringUtils.isBlank(detailVO.getIdcard())) {
                                        if (SessionUtil.getFullName().equalsIgnoreCase(detailVO.getFullName())) {
                                            canEnroll = true;
                                            break;
                                        }
                                    } else {
                                        if (SessionUtil.getSessionInfo().getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                            canEnroll = true;
                                            break;
                                        }
                                        if (eduStudentEnroll.getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                            canEnroll = true;
                                            break;
                                        }
                                    }
                                }

                            }

                        }
                        if (!canEnroll) {
                            throw new AppException("您不是房产所有者，不能报名，请使用房产证上的权利人账号登录系统进行报名。");
                        }

                    }
                }
            }
        } else {
            eduStudentEnroll.setRealProperty(null);
            eduStudentEnroll.setRealPropertyNum(null);
            eduStudentEnroll.setRegisterDate(null);
            eduStudentEnroll.setQlrName(null);
            eduStudentEnroll.setHouseAdreess(null);
        }
        eduStudentEnroll.setHouseId(vo.getHouseId());
        eduStudentEnroll.setParam6(vo.getParam6());
        eduStudentEnroll.setParam12(vo.getParam12());
        eduStudentEnroll.setParam13(vo.getParam13());
        eduStudentEnroll.setParam14(vo.getParam14());
        eduStudentEnroll.setParam15(vo.getParam15());
        eduStudentEnroll.setParam16(vo.getParam16());
        eduStudentEnroll.setParam17(vo.getParam17());
        eduStudentEnroll.setConfigName(vo.getConfigName());
        eduStudentEnroll.setConfigNameAlias(vo.getConfigNameAlias());
        eduStudentEnroll.setAborigineFlag(vo.getAborigineFlag());
        eduStudentEnroll.setServiceFlag(vo.getServiceFlag());
        eduStudentEnroll.setEnrollStatus(eduStudentEnroll.getParam7());
        eduStudentEnrollService.updateById(eduStudentEnroll);
        LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(EduStudentEnrollPre::getStudentEnrollPreId).eq(EduStudentEnrollPre::getYear, eduStudentEnroll.getYear())
                .eq(EduStudentEnrollPre::getIdcard, eduStudentEnroll.getIdcard());
        List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(preList)) {
            for (EduStudentEnrollPre pre : preList) {
                eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
            }
        }
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0077", title = "学校驳回让家长重新提交材料", funcType = FuncTypeEnum.edit)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0077",
            operationName = "学校驳回让家长重新提交材料",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void resubmitBh(EduStudentEnrollBhVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getParam8())) {
            throw new AppException("驳回原因不能为空");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (eduStudentEnroll == null) {
            throw new AppException("报名信息不存在");
        }
        if (!EnrollStatusFormalEnum.hy.getType().equals(eduStudentEnroll.getEnrollStatus())
                && !EnrollStatusFormalEnum.dsh.getType().equals(eduStudentEnroll.getEnrollStatus())
                && !EnrollStatusFormalEnum.dlq.getType().equals(eduStudentEnroll.getEnrollStatus())) {
            throw new AppException("只有审核中才能驳回");
        }
        eduStudentEnroll.setParam7(eduStudentEnroll.getEnrollStatus());
        eduStudentEnroll.setParam8(vo.getParam8());
        eduStudentEnroll.setEnrollStatus(EnrollStatusFormalEnum.bh.getType());
        eduStudentEnrollService.updateById(eduStudentEnroll);
        LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(EduStudentEnrollPre::getStudentEnrollPreId).eq(EduStudentEnrollPre::getYear, eduStudentEnroll.getYear())
                .eq(EduStudentEnrollPre::getIdcard, eduStudentEnroll.getIdcard());
        List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(preList)) {
            for (EduStudentEnrollPre pre : preList) {
                eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
            }
        }
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
    }

    //动态调用报名个性化方法
    private SaveStudentEnrollVO saveEnroll(SaveStudentEnrollVO vo) {
        EduSchoolVO schoolVO = eduSchoolService.getDetail(vo.getSchoolId());
        if (schoolVO == null) {
            throw new AppException("报名的学校不存在");
        }
        if(vo.getManagerFlag() == null){
            vo.setManagerFlag(false);
        }
        if(vo.getLrFlag() == null){
            vo.setLrFlag(false);
        }
        //如果是线下录入，但不是管理员录入，才去校验指标
        if (vo.getLrFlag() && !vo.getManagerFlag()) {
            //判断学校录入指标管理是否有配置存在
            QueryWrapper<EduSchoolLr> lrQueryWrapper = new QueryWrapper<>();
            lrQueryWrapper.lambda()
                    .eq(EduSchoolLr::getYear, vo.getYear())
                    .eq(EduSchoolLr::getSchoolId, vo.getSchoolId());
            EduSchoolLr schoolLr = eduSchoolLrService.getOne(lrQueryWrapper, false);
            if (ObjectUtils.isEmpty(schoolLr)) {
                throw new AppException("未配置学校线下录入指标，请联系教育局进行配置");
            }
            if (schoolLr.getLrCount() == 0) {
                throw new AppException(schoolLr.getSchoolName() + "的可录入人数为0，请联系教育局进行配置！");
            }
            List<String> statusList = new ArrayList<>();
            statusList.add(EnrollStatusFormalEnum.dsh.getType());
            statusList.add(EnrollStatusFormalEnum.hy.getType());
            statusList.add(EnrollStatusFormalEnum.lq.getType());
            statusList.add(EnrollStatusFormalEnum.fs.getType());
            statusList.add(EnrollStatusFormalEnum.dlq.getType());
            long enrollStudentCount = eduStudentEnrollService.count(Wrappers.<EduStudentEnroll>lambdaQuery()
                    .eq(EduStudentEnroll::getYear, vo.getYear())
                    .in(EduStudentEnroll::getEnrollStatus, statusList)
                    .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                    .eq(EduStudentEnroll::getSource, "6"));
            if (enrollStudentCount >= schoolLr.getLrCount()) {
                throw new AppException("学校线下录入的人数大于系统配置人数指标，无法进行学生录入，请联系教育局进行配置");
            }
        }

        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAccessToken(vo.getAccessToken());
        queryVO.setAreaCode(schoolVO.getAreaCode());
        queryVO.setEduConfigKey("saveEnroll");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel != null) {
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {
                    apiModel.getMethod().invoke(bean, vo);
                    eduEnrollClearCacheHelper.clearCacheMyEnroll(vo.getIdcard());
                    eduEnrollClearCacheHelper.clearCacheMyEnroll(vo.getFatherIdcard());
                    eduEnrollClearCacheHelper.clearCacheMyEnroll(vo.getMotherIdcard());
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(vo.getIdcard());
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(vo.getFatherIdcard());
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(vo.getMotherIdcard());
                    eduEnrollClearCacheHelper.clearCachePreBefore(vo.getStudentEnrollPreId());
                } else {
                    throw new AppException(schoolVO.getAreaCode() + "未找到处理报名保存的个性化方法");
                }
            } catch (AppException e) {
                throw e;
            } catch (InvocationTargetException e) {
                try {
                    AppException exception = (AppException) e.getTargetException();
                    throw new AppException(exception.getMsg(), e.getTargetException());
                } catch (Exception ex) {
                    throw new AppException(e.getCause().getMessage(), e.getTargetException());
                }

            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        } else {
            throw new AppException(schoolVO.getAreaCode() + "未找到处理报名保存的个性化方法");
        }
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0005", title = "学生正式报名管理修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0005",
            operationName = "学生正式报名管理修改",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollVO edit(EduStudentEnrollVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAuthStatus())) {
            throw new AppException("审核状态不能为空");
        }
        //判断数据是否已经迁移
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),STUDENT_ENROLL_TABLE);
        if (!queryHistoryFlag) {
            EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
            if (old == null) {
                throw new AppException("报名数据不存在，可能已被退回");
            }
        }else{
            throw new AppException("历史数据无法修改");
        }
        EduStudentEnroll studentEnroll = Convert.convert(EduStudentEnroll.class, vo);
        //处理传值为false或true时报长度错误
        if (StringUtils.isNotBlank(studentEnroll.getQyFlag())&& studentEnroll.getQyFlag().equalsIgnoreCase("true")) {
            studentEnroll.setQyFlag(BoolEnum.TRUE.getType());
        } else {
            studentEnroll.setQyFlag(BoolEnum.FALSE.getType());
        }
        if (AuthStatusEnum.NODO.getType().equals(studentEnroll.getAuthStatus())) {
            //待审核
            studentEnroll.setAdmitFlag(null);
            studentEnroll.setAdmitTime(null);
            studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());

        }
        if (AuthStatusEnum.NO.getType().equals(studentEnroll.getAuthStatus())) {
            //审核不通过
            studentEnroll.setAdmitFlag(BoolEnum.FALSE.getType());
            studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
            if (studentEnroll.getAdmitTime() == null) {
                studentEnroll.setAdmitTime(new Date());
            }
            studentEnroll.setAdmitUserId(SessionUtil.getUserId());
        }
        if (AuthStatusEnum.YES.getType().equals(studentEnroll.getAuthStatus())) {
            if (StringUtils.isBlank(studentEnroll.getAdmitFlag()) || "2".equals(studentEnroll.getAdmitFlag())) {
                studentEnroll.setAdmitFlag(null);
                studentEnroll.setAdmitTime(null);
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dlq.getType());
            } else if (BoolEnum.TRUE.getType().equals(studentEnroll.getAdmitFlag())) {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.lq.getType());
                if (studentEnroll.getAdmitTime() == null) {
                    studentEnroll.setAdmitTime(new Date());
                }
            } else {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
                if (studentEnroll.getAdmitTime() == null) {
                    studentEnroll.setAdmitTime(new Date());
                }
            }
        }
        eduStudentEnrollService.updateById(studentEnroll);
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getMotherIdcard());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0006", title = "学生正式报名管理根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0006",
            operationName = "学生正式报名管理删除",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduStudentEnrollKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getStudentEnrollId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduStudentEnroll entity = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduStudentEnrollService.removeById(vo.getStudentEnrollId());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(entity.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(entity.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(entity.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getMotherIdcard());
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(EduStudentEnrollPre::getStudentEnrollPreId)
                .eq(EduStudentEnrollPre::getIdcard, entity.getIdcard())
                .eq(EduStudentEnrollPre::getYear, entity.getYear());
        EduStudentEnrollPre pre = eduStudentEnrollPreService.getOne(queryWrapper, false);
        if (pre != null) {
            eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
        }

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0007", title = "app端判断登录账号是否学生", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public Boolean UserIsStudent(BaseVO vo) {
        String idcard = SessionUtil.getSessionInfo().getIdcard();
        EduOperationCacheDetailVO eduOperationCacheDetailVO = operationCacheIntegration.getPeriodYear();
        Integer year = eduOperationCacheDetailVO.getYear();
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollPre::getIdcard, idcard)
                .eq(EduStudentEnrollPre::getYear, year);
        return eduStudentEnrollPreService.count(queryWrapper) > 0;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0049", title = "app端判断是否可以摇号绑定", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public List<BindEnrollVO> checkBind(BindEnrollQueryVO vo) {
        if (StringUtils.isBlank(vo.getSchoolId())) {
            throw new AppException("报名学校id不能为空");
        }
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            throw new AppException("当前报名人员id不能为空");
        }
        EduStudentEnrollPreKeyVO keyVO = Convert.convert(EduStudentEnrollPreKeyVO.class, vo);
        EduStudentEnrollPreVO preVO = eduStudentEnrollBeforeJhIntegration.getPreDetail(keyVO);
        String idcard = SessionUtil.getSessionInfo().getIdcard();
        Integer year = eduHelper.thisYear();
        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(EduStudentEnroll::getIdcard, EduStudentEnroll::getFullName, EduStudentEnroll::getBindFlag, EduStudentEnroll::getConfigTypeName, EduStudentEnroll::getConfigName)
                .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getBirthYmd, preVO.getBirthYmd())
                .eq(EduStudentEnroll::getFatherIdcard, idcard)
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dsh.getType());
        List<EduStudentEnroll> faList = eduStudentEnrollService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(faList)) {
            return Convert.toList(BindEnrollVO.class, faList);
        }
        QueryWrapper<EduStudentEnroll> moQuery = new QueryWrapper<>();
        moQuery.lambda().select(EduStudentEnroll::getIdcard, EduStudentEnroll::getFullName, EduStudentEnroll::getBindFlag, EduStudentEnroll::getConfigTypeName, EduStudentEnroll::getConfigName).eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getMotherIdcard, idcard)
                .eq(EduStudentEnroll::getBirthYmd, preVO.getBirthYmd())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dsh.getType());
        List<EduStudentEnroll> moList = eduStudentEnrollService.list(moQuery);
        if (!CollectionUtils.isEmpty(moList)) {
            return Convert.toList(BindEnrollVO.class, moList);
        }
        return new ArrayList<>();
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0008", title = "app端我的报名查询", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public List<MyYearEnrollVO> getMyEnrollInfo(MyEnrollQueryVO vo) {
        //是否允许查看我的报名
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("queryEnrollFlag");
        String queryEnrollFlag = commonIntegration.getValueByKey(commonVO);
        if("0".equals(queryEnrollFlag)){
            return new ArrayList<>();
        }


        if (vo.getHiddenFlag() == null) {
            vo.setHiddenFlag(true);
        }
        String idcard = SessionUtil.getSessionInfo().getIdcard();
        List<StudentFormVO> myEnrollInfoList = eduStudentEnrollKindergartenService.getMyNurseryInfo(idcard);
        if (CollectionUtils.isEmpty(myEnrollInfoList)) {
            return new ArrayList<>();
        }
        dictHelper.valueToName(myEnrollInfoList, Arrays.asList(EduStudentEnrollDictEnum.values()));
        //调用个性化处理
        List<StudentFormVO> myEnrollInfo = new ArrayList<>();
        //判断是否正式报名时间
        Integer year=eduHelper.thisYear();

        for (StudentFormVO studentFormVO : myEnrollInfoList) {
            if (StringUtils.isNotBlank(studentFormVO.getAreaCode())) {
                if (studentFormVO.getYear()==year) {
                    EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
                    queryVO.setClassify("2");
                    queryVO.setAreaCode(studentFormVO.getAreaCode());
                    queryVO.setYear(studentFormVO.getYear());
                    EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
                    Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
                    EduOperationCacheDetailVO bmOperation=operation.get("YW002");//报名时间
                    //模拟报名只有正式报名2天之前才显示，之后时间不再显示
                    if (bmOperation!=null&&bmOperation.getBegTime()!=null) {
                        if (new Date().before(DateUtil.offsetDay(bmOperation.getBegTime(), -2))) {
                            myEnrollInfo.add(studentFormVO);
                        }else{
                            if (!"1".equals(studentFormVO.getImitateFlag())){
                                myEnrollInfo.add(studentFormVO);
                            }
                        }
                    }else{
                        myEnrollInfo.add(studentFormVO);
                    }
                }else{
                    if (!"1".equals(studentFormVO.getImitateFlag())){
                        myEnrollInfo.add(studentFormVO);
                    }
                }

            }
        }
        if (CollectionUtils.isEmpty(myEnrollInfo)) {
            return new ArrayList<>();
        }
        Map<String, List<StudentFormVO>> areaCodeGroupBy = myEnrollInfo.stream().collect(Collectors.groupingBy(StudentFormVO::getAreaCode));
        for (String areaCode : areaCodeGroupBy.keySet()) {
            EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
            queryVO.setAccessToken(vo.getAccessToken());
            queryVO.setAreaCode(areaCode);
            queryVO.setEduConfigKey("getMyEnrollInfo");
            String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
            ApiModel apiModel = apiContainer.get(funcCode);
            if (apiModel != null) {
                try {
                    Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                    if (null != bean) {
                        apiModel.getMethod().invoke(bean, areaCodeGroupBy.get(areaCode));
                    } else {
                        throw new AppException(areaCode + "未找到处理我的报名的个性化方法");
                    }
                } catch (AppException e) {
                    throw e;
                } catch (InvocationTargetException e) {
                    try {
                        AppException exception = (AppException) e.getTargetException();
                        throw new AppException(exception.getMsg(), e.getTargetException());
                    } catch (Exception ex) {
                        throw new AppException(e.getCause().getMessage(), e.getTargetException());
                    }

                } catch (Exception e) {
                    throw new AppException(e.getMessage(), e);
                }
            } else {
                throw new AppException(areaCode + "未找到处理我的报名的个性化方法");
            }
        }
        Map<Integer, List<StudentFormVO>> yearGroupBy = myEnrollInfo.stream().collect(Collectors.groupingBy(StudentFormVO::getYear));
        List<MyYearEnrollVO> mapList = new ArrayList<>();
        for (Integer key : yearGroupBy.keySet()) {
            //判断是否在年度招生时间中
            MyYearEnrollVO myYearEnrollVO = new MyYearEnrollVO();
            myYearEnrollVO.setYear(key);
            List<StudentFormVO> xsList = yearGroupBy.get(key);
            List<MyEnrollVO> myEnrollVOList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(xsList)) {
                Map<String, List<StudentFormVO>> xsGroupBy = xsList.stream().collect(Collectors.groupingBy(StudentFormVO::getChildIdcard));
                for (String xs : xsGroupBy.keySet()) {
                    List<StudentFormVO> bmList = xsGroupBy.get(xs);
                    if (!CollectionUtils.isEmpty(bmList)) {
                        MyEnrollVO myEnrollVO = Convert.convert(MyEnrollVO.class, bmList.get(0));
                        if (vo.getHiddenFlag()) {
                            myEnrollVO.setChildIdcard(DesensitizeUtil.getIdcard(myEnrollVO.getChildIdcard()));
                            myEnrollVO.setChildFullName(DesensitizeUtil.getFullName(myEnrollVO.getChildFullName()));
                        }
                        for (StudentFormVO formVO : bmList) {
                            if (formVO.getEnrollNum()==null) {
                                formVO.setEnrollNum(1);
                                if (BoolEnum.TRUE.getType().equalsIgnoreCase(formVO.getBbFlag())) {
                                    formVO.setEnrollNum(2);
                                }
                                if (BoolEnum.TRUE.getType().equalsIgnoreCase(formVO.getSpareRegisterFlag())) {
                                    formVO.setEnrollNum(3);
                                }
                            }
                            if (year - formVO.getYear() == 0 && EnrollStatusFormalEnum.lq.getType().equalsIgnoreCase(formVO.getEnrollStatus())) {
                                //判断是否显示推送
                                QueryWrapper<EduPushparents> queryWrapper = new QueryWrapper<>();
                                queryWrapper.lambda().eq(EduPushparents::getAreaCode, formVO.getAreaCode())
                                        .eq(EduPushparents::getYear, formVO.getYear())
                                        .eq(EduPushparents::getPushStatus, "1")
                                        .eq(EduPushparents::getSchoolCategory, formVO.getSchoolCategory())
                                        .eq(EduPushparents::getEnrollNum, formVO.getEnrollNum());
                                if (eduPushparentsService.count(queryWrapper) <= 0) {
                                    formVO.setEnrollStatusName("复审通过");
                                    formVO.setEnrollStatus("8");
                                }
                            }
                            if (year - formVO.getYear() == 0 && SchoolNatureEnum.gb.getType().equalsIgnoreCase(formVO.getSchoolNature())
                                    && EnrollStatusFormalEnum.ywblq.getType().equalsIgnoreCase(formVO.getEnrollStatus())
                                    && AuthStatusEnum.YES.getType().equalsIgnoreCase(formVO.getAuthStatus())) {
                                //查询调剂时间
                                EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
                                queryVO.setOperating("YW059");
                                queryVO.setAreaCode(formVO.getAreaCode());
                                queryVO.setYear(year);
                                queryVO.setClassify("2");
                                EduOperationCacheDetailVO bmOption = eduSystemConfigIntegration.getEduOperationOne(queryVO);
                                boolean tjTimeFlag = false;
                                if (bmOption == null) {
                                    tjTimeFlag = false;
                                } else {
                                    if (bmOption.isFlag()) {
                                        tjTimeFlag = true;
                                    }else{
                                        if ("2".equalsIgnoreCase(bmOption.getType())){
                                            tjTimeFlag = true;
                                        }
                                    }
                                }
                                if (tjTimeFlag) {
                                    //业务不予录取，查询是否可调剂
                                    QueryWrapper<EduSchoolTj> queryWrapper = new QueryWrapper<>();
                                    queryWrapper.lambda().eq(EduSchoolTj::getFromSchoolId, formVO.getSchoolId())
                                            .eq(EduSchoolTj::getFromConfigName, formVO.getConfigName())
                                            .eq(EduSchoolTj::getFlag, BoolEnum.TRUE.getType())
                                            .eq(EduSchoolTj::getYear, formVO.getYear());
                                    formVO.setTjStatus("1");//默认设置不能调剂
                                    if (eduSchoolTjService.count(queryWrapper) > 0) {
                                        formVO.setTjStatus("2");//待申请
                                        //判断是否调剂申请
                                        QueryWrapper<EduStudentTj> tjQueryWrapper = new QueryWrapper<>();
                                        tjQueryWrapper.lambda().eq(EduStudentTj::getStudentEnrollId, formVO.getStudentEnrollId())
                                                .orderByAsc(EduStudentTj::getTjType, EduStudentTj::getAspirationType);
                                        List<EduStudentTj> eduStudentTjList = eduStudentTjService.list(tjQueryWrapper);
                                        if (!CollectionUtils.isEmpty(eduStudentTjList)) {
                                            formVO.setTjList(Convert.toList(EduStudentTjVO.class, eduStudentTjList));
                                            for (EduStudentTj tj : eduStudentTjList) {
                                                if (BoolEnum.TRUE.getType().equalsIgnoreCase(tj.getCurrentFlag())) {
                                                    if (AuthStatusEnum.NODO.getType().equalsIgnoreCase(tj.getAuthStatus())) {
                                                        formVO.setTjStatus("3");//已申请
                                                    }
                                                    if (AuthStatusEnum.YES.getType().equalsIgnoreCase(tj.getAuthStatus())) {
                                                        formVO.setTjStatus("4");//调剂完成
                                                    }
                                                    break;
                                                }

                                            }
                                        }
                                    }
                                } else {
                                    formVO.setTjStatus("1");
                                }
                            } else {
                                formVO.setTjStatus("1");
                            }
                            if (StringUtils.isBlank(formVO.getConfigName())) {
                                formVO.setConfigName(formVO.getConfigTypeName());
                            }
                        }
                        myEnrollVO.setEnrollList(bmList);
                        myEnrollVOList.add(myEnrollVO);
                    }
                }
            }
            if (!CollectionUtils.isEmpty(myEnrollVOList)) {
                myYearEnrollVO.setEnrollList(myEnrollVOList);
                mapList.add(myYearEnrollVO);
            }
            //降序
            mapList.sort(Comparator.comparing(MyYearEnrollVO::getYear).reversed());
        }
        return mapList;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0009", title = "查询校验报名情况", funcType = FuncTypeEnum.query)
    public Boolean checkEnroll(YjbmQueryVO vo) {
        EduStudentEnrollPre eduStudentEnrollPre = getPre(vo.getStudentEnrollPreId(), vo.getIdcard());
        if (eduStudentEnrollPre == null) {
            throw new AppException("未找到新生登记信息");
        }
        return this.checkEnroll(eduStudentEnrollPre);
    }

    @Override
    public Boolean checkEnroll(EduStudentEnrollPre eduStudentEnrollPre) {
        return checkEnroll(eduStudentEnrollPre.getIdcard(), eduStudentEnrollPre.getYear());

    }

    @Override
    public Boolean checkEnroll(String idcard, Integer year) {
        if (year == null) {
            EduOperationCacheDetailVO eduOperationCacheDetailVO = operationCacheIntegration.getPeriodYear();
            year = eduOperationCacheDetailVO.getYear();
        }
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.bh.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getIdcard).eq(EduStudentEnroll::getIdcard, idcard)
                .eq(EduStudentEnroll::getYear, year)
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
        if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
            return false;
        }
        return true;
    }

    @Override
    public EduStudentEnrollPre getPre(String studentEnrollPreId, String idcard) {

        if (StringUtils.isNotBlank(studentEnrollPreId)) {
            EduStudentEnrollPre eduStudentEnrollPre =
                    eduStudentEnrollPreService.getById(studentEnrollPreId);
            if (eduStudentEnrollPre == null) {
                throw new AppException("未找到预采集数据");
            }
            if (!AuthStatusEnum.YES.getType().equals(eduStudentEnrollPre.getAuthStatus())) {
                throw new AppException("该预采集未审核或者审核不通过");
            }
            return eduStudentEnrollPre;
        }
        if (StringUtils.isNotBlank(idcard)) {
            Integer year = eduHelper.thisYear();
            QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnrollPre::getIdcard, idcard)
                    .eq(EduStudentEnrollPre::getYear, year)
                    .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType());
            List<EduStudentEnrollPre> list = eduStudentEnrollPreService.list(queryWrapper);
            if (CollectionUtils.isEmpty(list)) {
                throw new AppException("未找到有效的学生数据，请先办理准新生登记");
            } else {
                if (list.size() > 1) {
                    throw new AppException("存在多条数据，请联系学校或者技术人员");
                }
                return list.get(0);
            }
        } else {
            throw new AppException("学生身份证或者预采集信息不能为空");
        }

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0010", title = "校验是否可以摇号导出", funcType = FuncTypeEnum.query)
    public void checkYhExp(EduStudentEnrollQueryVO vo) {
        String schoolId = vo.getSchoolId();
        if (StringUtils.isBlank(schoolId)) {
            schoolId = SessionUtil.getSessionInfo().getOrgId();
        }
        if (StringUtils.isBlank(vo.getConfigTypeName())) {
            throw new AppException("请先选择报名类型");
        }
        int year = eduHelper.thisYear();

        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        //判断是否有未审核数据
        QueryWrapper<EduStudentEnroll> wshQuery = new QueryWrapper<>();
        wshQuery.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getAreaCode, vo.getAreaCode())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dsh.getType())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType());
        long wshCount = eduStudentEnrollService.count(wshQuery);
        if (wshCount > 0) {
            throw new AppException("存在未审核数据，请先审核后导出");
        }
        //判断是否存在摇号排序号，存在的情况下不允许导出
        QueryWrapper<EduStudentEnroll> pxhQuery = new QueryWrapper<>();
        pxhQuery.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getAreaCode, vo.getAreaCode())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType())
                .isNotNull(EduStudentEnroll::getSerialNum)
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType());
        long pxhCount = eduStudentEnrollService.count(pxhQuery);
        if (pxhCount > 0) {
            throw new AppException("已存在摇号排序号，不能导出");
        }
        //判断审核通过是否大于计划数

        //待录取人数
        QueryWrapper<EduStudentEnroll> dlqQuery = new QueryWrapper<>();
        dlqQuery.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getAreaCode, vo.getAreaCode())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType());
        long dlyCount = eduStudentEnrollService.count(dlqQuery);
        if (dlyCount == 0) {
            throw new AppException("没有待录取数据，不能导出");
        }
        QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                .eq(EduSchoolConfig::getSchoolId, schoolId)
                .eq(EduSchoolConfig::getAreaCode, vo.getAreaCode())
                .eq(EduSchoolConfig::getYear, year)
                .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                .eq(EduSchoolConfig::getConfigTypeName, vo.getConfigTypeName());
        QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
        brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, year)
                .eq(EduEnrollmenBrochure::getSchoolId, schoolId);
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }
        EduSchool eduSchool = eduSchoolService.getById(schoolId);
        EduSchoolConfig eduSchoolConfig = eduSchoolConfigService.getOne(configQueryWrapper, false);
        if (eduSchoolConfig == null) {
            throw new AppException("未配置招生计划");
        }
        //计划人数
        Integer enrolment = 0;
        if (eduSchoolConfig != null) {
            enrolment = eduSchoolConfig.getEnrolment() == null ? 0 : eduSchoolConfig.getEnrolment();
        }
        //已录取人数
        QueryWrapper<EduStudentEnroll> ylqQuery = new QueryWrapper<>();
        ylqQuery.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getAreaCode, vo.getAreaCode())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType());
        long ylqCount = eduStudentEnrollService.count(ylqQuery);

        if (ylqCount + dlyCount <= enrolment) {
            throw new AppException("录取人数小于计划数，无需摇号");
        }
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0011", title = "义务教育民转公报名摇号信息导出", funcType = FuncTypeEnum.other)
    public void exportYwMzgApplyInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        vo.setOpType("2");
        this.exportYwApplyInfo(vo, response);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0012", title = "义务教育民转公摇号信息导入", funcType = FuncTypeEnum.other)
    public YwMbApplyFileVO inputYwMzgApplyInfo(YwMbApplyFileVO vo, MultipartFile file) {
        return this.inputYwMbApplyInfo(vo, file);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0013", title = "获取义务教育报名单个明细", funcType = FuncTypeEnum.query)
    public EduStudentEnrollVO getYwApplyDetail(EduStudentEnrollKeyVO vo) {

        return this.getYwApplyById(vo);
    }

    @Override
    public EduStudentEnrollVO getYwApplyById(EduStudentEnrollKeyVO vo) {
        String studentEnrollId = vo.getStudentEnrollId();
        Assert.hasText(studentEnrollId, "义务教育学生报名id不能为空");
        EduStudentEnrollQueryVO queryVO = new EduStudentEnrollQueryVO();
        queryVO.setStudentEnrollId(studentEnrollId);
        if(vo.getYear()==null){
            vo.setYear(eduHelper.thisYear());
        }
        List<EduStudentEnrollVO> list = new ArrayList<>();
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),STUDENT_ENROLL_TABLE);
        if (!queryHistoryFlag) {
             list = eduStudentEnrollService.getYwApplyList(queryVO);
        } else {
             list = eduhStudentEnrollService.getYwApplyListYq(queryVO);
             //解密
            for (EduStudentEnrollVO studentEnroll : list) {
                if ("1".equals(studentEnroll.getEncryptFlag())){
                    eduStudentEnrollService.decrypt(studentEnroll);
                }
            }
        }
        if (CollectionUtils.isEmpty(list)) {
            throw new AppException("未找到报名信息，请刷新页面后重新再试");
        }
        EduStudentEnrollVO studentEnrollVO = Convert.convert(EduStudentEnrollVO.class, list.get(0));
        List<String> areaCodeList = new ArrayList<>();
        //获取当前部署行政区划

        DictAreaVO dictAreaVO = new DictAreaVO();
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        if (!CollectionUtils.isEmpty(districtByOrg)) {
            areaCodeList = districtByOrg.stream().map(SelectVO::getDictKey).distinct().collect(Collectors.toList());
        } else {
            areaCodeList.add(studentEnrollVO.getAreaCode());
        }

        /*
         * source:6 学校录入报名数据
         * */
        if (StringUtils.isNotEmpty(studentEnrollVO.getSource())) {
            if ("6".equals(studentEnrollVO.getSource())) {
                studentEnrollVO.setFileInfo(studentEnrollVO.getParam20());
            }
        }

        String formId = studentEnrollVO.getFormId();
        if ("0".equals(studentEnrollVO.getSchoolNature())
                && !BoolEnum.TRUE.getType().equals(studentEnrollVO.getSpecialFlag())
                && !"直升".equals(studentEnrollVO.getConfigName())&&!"FG类人才".equals(studentEnrollVO.getConfigName())
                && ObjectUtils.isEmpty(formId)) {
            throw new AppException("数据异常：报名表单id为空，请联系系统管理员");
        }
        int year = studentEnrollVO.getYear();
        List<EduFormEnrollParams> configList = null;
        if (studentEnrollVO != null && StringUtils.isNotBlank(formId)) {
            if (BoolEnum.TRUE.getType().equals(studentEnrollVO.getSpecialFlag())) {
                //特殊通道
                QueryWrapper<EduFormSpecialParams> configQueryWrapper = new QueryWrapper<>();
                configQueryWrapper.lambda().eq(EduFormSpecialParams::getFormSpecialId, formId);
                List<EduFormSpecialParams> formSpecialList = eduFormSpecialParamsService.list(configQueryWrapper);
                if (!CollectionUtils.isEmpty(formSpecialList)) {
                    configList = Convert.toList(EduFormEnrollParams.class, formSpecialList);
                }
            } else {
                QueryWrapper<EduFormEnrollParams> configQueryWrapper = new QueryWrapper<>();
                configQueryWrapper.lambda().eq(EduFormEnrollParams::getFormId, formId);
                configList = eduFormEnrollParamsService.list(configQueryWrapper);
            }
        }

        studentEnrollVO.setXjFlag(false);
        studentEnrollVO.setSbFlag(false);
        studentEnrollVO.setHjFlag(false);
        studentEnrollVO.setFcFlag(false);
        studentEnrollVO.setQyFlag(false);
        studentEnrollVO.setJzzFlag(false);
        studentEnrollVO.setWqFlag(false);
        studentEnrollVO.setHjDsjFlag(false);
        studentEnrollVO.setFcDsjFlag(false);
        List<EduFormEnrollParamsVO> formConfigVOList = new ArrayList<>();
        List<String> idcardList = new ArrayList<>();
        idcardList.add(studentEnrollVO.getIdcard());
        if (StringUtils.isNotBlank(studentEnrollVO.getFatherIdcard())) {
            idcardList.add(studentEnrollVO.getFatherIdcard());
        }
        if (StringUtils.isNotBlank(studentEnrollVO.getMotherIdcard())) {
            idcardList.add(studentEnrollVO.getMotherIdcard());
        }
        if ("0".equals(studentEnrollVO.getSchoolNature())) {
            //公办学校处理
            if ("A".equals(studentEnrollVO.getConfigName())) {
                studentEnrollVO.setHjFlag(true);
                studentEnrollVO.setFcFlag(true);
                if (BoolEnum.TRUE.getType().equals(studentEnrollVO.getAborigineFlag())) {
                    studentEnrollVO.setFcDsjFlag(true);
                }
            }
            if ("B".equals(studentEnrollVO.getConfigName())) {
                studentEnrollVO.setHjFlag(true);
                studentEnrollVO.setFcFlag(true);
                studentEnrollVO.setFcDsjFlag(true);

            }
            if ("C".equals(studentEnrollVO.getConfigName())) {
                studentEnrollVO.setFcFlag(true);
                studentEnrollVO.setHjDsjFlag(true);
            }
            if ("特殊户口".equals(studentEnrollVO.getConfigName())) {
                studentEnrollVO.setHjFlag(true);
                studentEnrollVO.setFcDsjFlag(true);
            }
            if ("E".equals(studentEnrollVO.getConfigName()) && BoolEnum.TRUE.getType().equalsIgnoreCase(studentEnrollVO.getAppointFlag())) {
                studentEnrollVO.setXjFlag(true);
            }


        }
        if (!CollectionUtils.isEmpty(configList)) {
            configList.forEach(item -> {
                if (StringUtils.equals(item.getPropertyType(), "4")) {
                    studentEnrollVO.setXjFlag(true);
                } else if (StringUtils.equals(item.getPropertyType(), "5")) {
                    studentEnrollVO.setHjFlag(true);
                } else if (StringUtils.equals(item.getPropertyType(), "6")) {
                    studentEnrollVO.setFcFlag(true);
                    studentEnrollVO.setHjDsjFlag(true);
                } else if (StringUtils.equals(item.getPropertyType(), "7")) {
                    studentEnrollVO.setWqFlag(true);

                } else if (StringUtils.equals(item.getPropertyType(), "8")) {

                    studentEnrollVO.setSbFlag(true);
                    studentEnrollVO.setHjDsjFlag(true);


                } else if (StringUtils.equals(item.getPropertyType(), "9")) {

                    studentEnrollVO.setQyFlag(true);

                } else if (StringUtils.equals(item.getPropertyType(), "10")) {

                    studentEnrollVO.setJzzFlag(true);
                    studentEnrollVO.setSbFlag(true);
                    studentEnrollVO.setHjDsjFlag(true);

                } else {
                    formConfigVOList.add(Convert.convert(EduFormEnrollParamsVO.class, item));
                }
            });

        }

        if (studentEnrollVO.getWqFlag()) {
            //网签
            if (StringUtils.isNotBlank(studentEnrollVO.getNetsignId())) {
                QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
                netsignQueryWrapper.lambda().eq(EduNetsign::getYear, year)
                        .eq(EduNetsign::getNetsignId, studentEnrollVO.getNetsignId())
                        .orderByAsc(EduNetsign::getBasj);
                List<EduNetsign> netsignList = eduNetsignService.list(netsignQueryWrapper);
                if (!CollectionUtils.isEmpty(netsignList)) {
                    List<EduNetsignVO> netsignVOList = Convert.toList(EduNetsignVO.class, netsignList);
                    for (EduNetsignVO eduNetsignVO : netsignVOList) {
                        if (StringUtils.isNotBlank(eduNetsignVO.getSchoolId())) {
                            EduSchoolVO eduSchool = eduSchoolService.getDetail(eduNetsignVO.getSchoolId());
                            if (eduSchool != null) {
                                eduNetsignVO.setSchoolName(eduSchool.getSchoolName());
                            }
                        }
                    }
                    studentEnrollVO.setWqList(netsignVOList);
                }
            }
        }
        if (studentEnrollVO.getSbFlag()) {
            //社保
            QueryWrapper<EduSocialSecurity> securityQueryWrapper = new QueryWrapper<>();
            securityQueryWrapper.lambda().eq(EduSocialSecurity::getYear, year)
                    .in(EduSocialSecurity::getAac147, idcardList)
                    .eq(EduSocialSecurity::getAac031, "1")
                    .eq(EduSocialSecurity::getAac008, "1")
                    .orderByAsc(EduSocialSecurity::getAac147).orderByAsc(EduSocialSecurity::getAae140).orderByAsc(EduSocialSecurity::getAae030);
            List<EduSocialSecurity> socialSecurityList = eduSocialSecurityService.list(securityQueryWrapper);
            if (!CollectionUtils.isEmpty(socialSecurityList)) {
                List<EduSocialSecurityVO> cbVOList = Convert.toList(EduSocialSecurityVO.class, socialSecurityList);
                for (EduSocialSecurityVO eduSocialSecurityVO : cbVOList) {
                    if ("1".equalsIgnoreCase(eduSocialSecurityVO.getAac008())) {
                        if ("1".equalsIgnoreCase(eduSocialSecurityVO.getAac031())) {
                            eduSocialSecurityVO.setStatus("1");
                            eduSocialSecurityVO.setStatusName("正常参保");
                        } else {
                            eduSocialSecurityVO.setStatus("2");
                            eduSocialSecurityVO.setStatusName("参保中断");
                        }
                    } else {
                        eduSocialSecurityVO.setStatus("3");
                        eduSocialSecurityVO.setStatusName("参保终止");
                    }
                    if (StringUtils.isNotBlank(eduSocialSecurityVO.getAab301())) {
                        DictQueryVO dictQueryVO = new DictQueryVO();
                        dictQueryVO.setDictField("AREA");
                        dictQueryVO.setDictKey(eduSocialSecurityVO.getAab301());
                        DictVO dictVo = dictIntegration.getDictByFieldAndKey(dictQueryVO);
                        if (!ObjectUtils.isEmpty(dictVo)) {
                            eduSocialSecurityVO.setAab301Name(dictVo.getDictValue());
                        } else if ("330799".equals(eduSocialSecurityVO.getAab301())) {
                            eduSocialSecurityVO.setAab301Name("市本级");
                        } else {
                            eduSocialSecurityVO.setAab301Name("未知");
                        }
                    }

                }

                studentEnrollVO.setSbList(cbVOList);
            }
        }
        if (studentEnrollVO.getQyFlag()) {
            //企业
            if (StringUtils.isNotBlank(studentEnrollVO.getCompanyId())) {
                QueryWrapper<EduCompany> companyQueryWrapper = new QueryWrapper<>();
                companyQueryWrapper.lambda().eq(EduCompany::getYear, year)
                        .eq(EduCompany::getCompanyId, studentEnrollVO.getCompanyId());
                List<EduCompany> companyList = eduCompanyService.list(companyQueryWrapper);
                if (!CollectionUtils.isEmpty(companyList)) {
                    List<CompanyVO> qyVOList = Convert.toList(CompanyVO.class, companyList);
                    studentEnrollVO.setQyList(qyVOList);
                }
            }
        }
        if (studentEnrollVO.getJzzFlag()) {
            //居住证
            if (StringUtils.isNotBlank(studentEnrollVO.getLivePlaceId())) {
                QueryWrapper<EduLivePlace> livePlaceQueryWrapper = new QueryWrapper<>();
                livePlaceQueryWrapper.lambda().eq(EduLivePlace::getYear, year)
                        .eq(EduLivePlace::getLivePlaceId, studentEnrollVO.getLivePlaceId()).orderByAsc(EduLivePlace::getSfzh);
                List<EduLivePlace> livePlaceList = eduLivePlaceService.list(livePlaceQueryWrapper);
                if (!CollectionUtils.isEmpty(livePlaceList)) {
                    List<LivePlaceVO> livePlaceVOList = Convert.toList(LivePlaceVO.class, livePlaceList);
                    for (LivePlaceVO live : livePlaceVOList) {
                        if (StringUtils.isNotBlank(live.getXzqhdm())) {
                            QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
                            queryWrapper.lambda()
                                    .eq(SysDict::getDictField, "AREA")
                                    .eq(SysDict::getDictKey, live.getXzqhdm());
                            SysDict areaNode = sysDictService.getOne(queryWrapper, false);
                            live.setXzqhdmName(areaNode.getDictValue());
                        }
                    }
                    studentEnrollVO.setJzzList(livePlaceVOList);
                }
            }
        }
        if (studentEnrollVO.getXjFlag()) {
            //学籍
            if (StringUtils.isNotBlank(studentEnrollVO.getStudentStatusId())) {
                EduStudentStatus studentStatus = eduStudentStatusService.getById(studentEnrollVO.getStudentStatusId());
                if (studentStatus != null) {
                    studentEnrollVO.setXjInfo(
                            Convert.convert(StudentStatusVO.class, studentStatus));
                }

            } else {
                QueryWrapper<EduStudentStatus> statusQueryWrapper = new QueryWrapper<>();
                statusQueryWrapper.lambda().eq(EduStudentStatus::getYear, studentEnrollVO.getYear())
                        .eq(EduStudentStatus::getIdcard, studentEnrollVO.getIdcard());
                List<EduStudentStatus> studentStatusList = eduStudentStatusService.list(statusQueryWrapper);
                if (!CollectionUtils.isEmpty(studentStatusList)) {
                    studentEnrollVO.setXjInfo(
                            Convert.convert(StudentStatusVO.class, studentStatusList.get(0)));
                }
            }
        }
        if (studentEnrollVO.getFcFlag()) {
            //如果是民转公
            if (SchoolNatureEnum.mzg.getType().equals(studentEnrollVO.getSchoolNature())) {
                //是否显示大数据房产信息
                CommonVO fcdsjFlagCheck = new CommonVO();
                fcdsjFlagCheck.setParamKey("SHOW_FCDSJFLAG");
                String showFcdsjFlag = commonIntegration.getValueByKey(fcdsjFlagCheck);
                if (BoolEnum.TRUE.getType().equals(showFcdsjFlag)) {
                    studentEnrollVO.setFcDsjFlag(true);
                }
                //是否显示大数据户籍信息
                CommonVO hjdsjFlagCheck = new CommonVO();
                hjdsjFlagCheck.setParamKey("SHOW_HJDSJFLAG");
                String showHjdsjFlag = commonIntegration.getValueByKey(hjdsjFlagCheck);
                if  (BoolEnum.TRUE.getType().equals(showHjdsjFlag)) {
                    studentEnrollVO.setHjDsjFlag(true);
                }
            }

            //房产
            if (StringUtils.isNotBlank(studentEnrollVO.getHouseId())) {
                boolean historyHouseFlag=false;
                EduHouse eduHouse = eduHouseService.getHouseById(studentEnrollVO.getHouseId());
                //数据为空去查询历史表
                if (ObjectUtils.isEmpty(eduHouse)) {
                    EduhHouse eduhHouse = eduhHouseService.getById(studentEnrollVO.getHouseId());
                    if (eduhHouse != null && eduhHouse.getStatus().equals(BoolEnum.TRUE.getType())) {
                        //判断是否加密过
                        if (EduStatusTypeEnum.success.getType().equals(eduhHouse.getEncryptFlag())) {
                            eduhHouseService.decrypt(eduhHouse);
                        }
                        studentEnrollVO.setFcInfo(
                                Convert.convert(EduHouseVO.class, eduhHouse));
                    }
                    historyHouseFlag=true;
                }
                if(eduHouse != null &&StringUtils.isNotBlank(eduHouse.getRealProperty())){
                    if (historyHouseFlag){
                        QueryWrapper<EduhHouse> houseQueryWrapper = new QueryWrapper<>();
                        houseQueryWrapper.lambda().eq(EduhHouse::getYear, studentEnrollVO.getYear())
                                .eq(EduhHouse::getRealProperty, eduHouse.getRealProperty())
                                .eq(EduhHouse::getStatus, BoolEnum.TRUE.getType());
                        List<EduhHouse> eduhHouseList = eduhHouseService.list(houseQueryWrapper);
                        if (!CollectionUtils.isEmpty(eduhHouseList)&&eduhHouseList.size()>1) {
                            String addressStr="";
                            for (EduhHouse eduhHouse : eduhHouseList) {
                                //判断是否加密过
                                if (EduStatusTypeEnum.success.getType().equals(eduhHouse.getEncryptFlag())) {
                                    eduhHouseService.decrypt(eduhHouse);
                                }
                                if (StringUtils.isBlank(eduhHouse.getAddress())){
                                    addressStr=eduhHouse.getAddress();
                                }else{
                                    addressStr=addressStr+","+eduhHouse.getAddress();
                                }
                            }
                            eduHouse.setAddress(addressStr);
                        }

                    }else {
                        QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                        houseQueryWrapper.lambda().eq(EduHouse::getYear, studentEnrollVO.getYear())
                                .eq(EduHouse::getRealProperty, eduHouse.getRealProperty())
                                .eq(EduHouse::getStatus, BoolEnum.TRUE.getType());
                        List<EduHouse> eduHouseList = eduHouseService.list(houseQueryWrapper);
                        if (!CollectionUtils.isEmpty(eduHouseList)&&eduHouseList.size()>1) {
                            String addressStr="";
                            for (EduHouse house : eduHouseList) {
                                if (StringUtils.isBlank(house.getAddress())){
                                    addressStr=house.getAddress();
                                }else{
                                    addressStr=addressStr+","+house.getAddress();
                                }
                            }
                            eduHouse.setAddress(addressStr);
                        }
                    }
                }
                if (eduHouse != null && eduHouse.getStatus().equals(BoolEnum.TRUE.getType()) && eduHouse.getAuthStatus().equals(AuthStatusEnum.YES.getType())) {
                    studentEnrollVO.setFcInfo(
                            Convert.convert(EduHouseVO.class, eduHouse));
                    studentEnrollVO.setHouseAdreess(eduHouse.getAddress());
                }
                if (studentEnrollVO.getFcInfo() != null) {
                    if (StringUtils.isNotBlank(studentEnrollVO.getFcInfo().getPrimarySchoolOne())) {
                        Double p = Double.parseDouble(studentEnrollVO.getFcInfo().getPrimarySchoolOne().replaceAll("%", ""));
                        if (p < 100) {
                            studentEnrollVO.setFcDsjFlag(true);
                        }
                    }

                }
            }
        }
        if (studentEnrollVO.getHjFlag()) {
            //如果是民转公
            if (SchoolNatureEnum.mzg.getType().equals(studentEnrollVO.getSchoolNature())) {
                //是否显示大数据房产信息
                CommonVO fcdsjFlagCheck = new CommonVO();
                fcdsjFlagCheck.setParamKey("SHOW_FCDSJFLAG");
                String showFcdsjFlag = commonIntegration.getValueByKey(fcdsjFlagCheck);
                if (BoolEnum.TRUE.getType().equals(showFcdsjFlag)) {
                    studentEnrollVO.setFcDsjFlag(true);
                }
                //是否显示大数据户籍信息
                CommonVO hjdsjFlagCheck = new CommonVO();
                hjdsjFlagCheck.setParamKey("SHOW_HJDSJFLAG");
                String showHjdsjFlag = commonIntegration.getValueByKey(hjdsjFlagCheck);
                if  (BoolEnum.TRUE.getType().equals(showHjdsjFlag)) {
                    studentEnrollVO.setHjDsjFlag(true);
                }
            }
            //户籍
            if (StringUtils.isNotBlank(studentEnrollVO.getHouseholdId())) {
                EduHousehold eduHousehold = eduHouseholdService.getHouseholdById(studentEnrollVO.getHouseholdId());
                if (eduHousehold != null && eduHousehold.getStatus().equals(BoolEnum.TRUE.getType())) {
                    studentEnrollVO.setHjInfo(
                            Convert.convert(EduHouseholdVO.class, eduHousehold));
                }
            }
        }
        if (studentEnrollVO.getConfigName().equalsIgnoreCase("房产")
                || studentEnrollVO.getConfigName().equalsIgnoreCase("户籍")
                || studentEnrollVO.getConfigName().equalsIgnoreCase("A")
                || studentEnrollVO.getConfigName().equalsIgnoreCase("B")
                || studentEnrollVO.getConfigName().equalsIgnoreCase("C")) {

            List<EduHouse> houseList = eduHouseService.getHouseByAllIdcard(idcardList, studentEnrollVO.getYear(), "1", null);
            if (!CollectionUtils.isEmpty(houseList)) {
                studentEnrollVO.setHasHouse(true);
                List<EduHouseVO> houseVOist = new ArrayList<>();
                for (EduHouse eduHouse : houseList) {
                    EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);
                    houseVO.setRealPropertyDetails(eduHouse.getRealProperty());
                    houseVOist.add(houseVO);
                }
                studentEnrollVO.setHouseList(houseVOist);
            } else {
                studentEnrollVO.setHasHouse(false);
                studentEnrollVO.setHouseList(new ArrayList<>());
            }

        }


        if (studentEnrollVO.getHjDsjFlag()) {
            String idcard = studentEnrollVO.getIdcard();
            QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduHousehold::getIdcard, idcard)
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getYear, studentEnrollVO.getYear())
                    .orderByDesc(EduHousehold::getQysj);
            List<EduHousehold> householdList = eduHouseholdService.list(queryWrapper);
            if (!CollectionUtils.isEmpty(householdList)) {
                EduHousehold eduHousehold = householdList.get(0);
                if (eduHousehold.getStatus().equals(BoolEnum.TRUE.getType())) {
                    studentEnrollVO.setHjDsjInfo(
                            Convert.convert(EduHouseholdVO.class, eduHousehold));
                }

            }


        }
        studentEnrollVO.setParamsVOList(formConfigVOList);
        //审核情况
        LambdaQueryWrapper<EduStudentEnrollReview> reviewLambdaQueryWrapper = new LambdaQueryWrapper<>();
        reviewLambdaQueryWrapper.select(EduStudentEnrollReview::getStudentEnrollId, EduStudentEnrollReview::getAuditType, EduStudentEnrollReview::getAuthStatus, EduStudentEnrollReview::getAuthRemarks, EduStudentEnrollReview::getAuthTime, EduStudentEnrollReview::getAuthUserName).eq(EduStudentEnrollReview::getStudentEnrollId, studentEnrollVO.getStudentEnrollId());
        List<EduStudentEnrollReview> reviewList = eduStudentEnrollReviewService.list(reviewLambdaQueryWrapper);
        if (!CollectionUtils.isEmpty(reviewList)) {
            studentEnrollVO.setReviewVOList(Convert.toList(EduStudentEnrollReviewVO.class, reviewList));
        }
        //查询户籍信息
        boolean houseHoldFlag = false;
        if (SchoolNatureEnum.mb.getType().equalsIgnoreCase(studentEnrollVO.getSchoolNature())) {
            if (StringUtils.isBlank(studentEnrollVO.getHouseholdAddress())) {
                houseHoldFlag = true;
            }
            if (!BoolEnum.TRUE.getType().equalsIgnoreCase(studentEnrollVO.getFollowingFlag())) {
                houseHoldFlag = true;
            }
        }
        if (houseHoldFlag) {
            QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
            householdQueryWrapper.lambda().select(EduHousehold::getAddress).eq(EduHousehold::getIdcard, studentEnrollVO.getIdcard())
                    .eq(EduHousehold::getAreaCode, studentEnrollVO.getAreaCode())
                    .in(EduHousehold::getAreaCode, areaCodeList)
                    .eq(EduHousehold::getYear, studentEnrollVO.getYear())
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType());
            List<EduHousehold> householdList = eduHouseholdService.list(householdQueryWrapper);
            if (!CollectionUtils.isEmpty(householdList)) {
                studentEnrollVO.setHasHousehold(true);
                studentEnrollVO.setFollowingFlag(BoolEnum.TRUE.getType());
                if (StringUtils.isBlank(studentEnrollVO.getHouseholdAddress())) {
                    studentEnrollVO.setHouseholdAddress(householdList.get(0).getAddress());
                }
            } else {
                studentEnrollVO.setHasHousehold(false);
            }
        }
        if (!VerificationAuthStatusEnum.wxhy.getType().equalsIgnoreCase(studentEnrollVO.getIcertificatioFlag())) {
            QueryWrapper<EduStudentEnrollVerification> queryVWrapper = new QueryWrapper<>();
            queryVWrapper.lambda().eq(EduStudentEnrollVerification::getStudentEnrollId, studentEnrollVO.getStudentEnrollId());
            List<EduStudentEnrollVerification> verificationList = eduStudentEnrollVerificationService.list(queryVWrapper);
            if (!CollectionUtils.isEmpty(verificationList)) {
                studentEnrollVO.setHyFlag(true);
                List<EduStudentEnrollVerificationVO> verificationVOList = Convert.toList(EduStudentEnrollVerificationVO.class, verificationList);
                dictHelper.valueToName(verificationVOList, Arrays.asList(VerificationEnum.values()));
                //遍历核验数据，根据核验类型设置核验材料列表
                Boolean qzgxVerificationFlag = false;
                String fhyzType = "";
                Integer fhyzIndex = 0;
                List<String> fhyzList = new ArrayList<>();
                fhyzList.add(VerificationTypeEnum.yzb.getType());
                fhyzList.add(VerificationTypeEnum.fwq.getType());
                fhyzList.add(VerificationTypeEnum.fhyz.getType());
                fhyzList.add(VerificationTypeEnum.fwqyzb.getType());
                for (EduStudentEnrollVerificationVO enrollVerification : verificationVOList) {
                    //设置核验材料
                    setVerificationMaterial(enrollVerification, studentEnrollVO);
                    if (VerificationTypeEnum.qzgx.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
                        qzgxVerificationFlag = true;
                    }
                    if (fhyzList.contains(enrollVerification.getVerificationType())) {
                        fhyzType = enrollVerification.getVerificationType();
                        fhyzIndex = verificationVOList.indexOf(enrollVerification);
                    }
                }
                Map<String, List<EduMateria>> verificationMap = verificationVOList.stream().
                        collect(Collectors.toMap(EduStudentEnrollVerificationVO::getVerificationType, EduStudentEnrollVerificationVO::getVerificationMateriaList, (k1, k2) -> k1));
                if (qzgxVerificationFlag) {
                    List<EduMateria> materiaList = verificationMap.get(fhyzType);
                    List<EduMateria> newMateriaList = new ArrayList<>();
                    if (!CollectionUtils.isEmpty(materiaList)) {
                        for (EduMateria eduMateria : materiaList) {
                            //排除户口本
                            if (!eduMateria.getMaterialName().equalsIgnoreCase("户口本")) {
                                newMateriaList.add(eduMateria);
                            }
                        }
                        verificationVOList.get(fhyzIndex).setVerificationMateriaList(newMateriaList);
                    }
                }
                studentEnrollVO.setVerificationVOList(verificationVOList);
            } else {
                studentEnrollVO.setHyFlag(false);
                studentEnrollVO.setVerificationVOList(new ArrayList<>());
            }
        } else {
            studentEnrollVO.setHyFlag(false);
        }
        if("1".equals(studentEnrollVO.getWhiteFlag())){
            //白名单处理
            QueryWrapper<EduStudentEnrollWhite> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().select(EduStudentEnrollWhite::getIdcard,EduStudentEnrollWhite::getRemark).eq(EduStudentEnrollWhite::getIdcard,studentEnrollVO.getIdcard())
                    .eq(EduStudentEnrollWhite::getYear,studentEnrollVO.getYear())
                    .eq(EduStudentEnrollWhite::getAuthStatus,AuthStatusEnum.YES.getType());
            EduStudentEnrollWhite eduStudentEnrollWhite = eduStudentEnrollWhiteService.getOne(queryWrapper,false);
            if (eduStudentEnrollWhite!=null){
                studentEnrollVO.setWhiteMsg(eduStudentEnrollWhite.getRemark());
            }

        }
        Integer thisYear = eduHelper.thisYear();
        Boolean desensitizeFlag = vo.getDesensitizeFlag();
        if (desensitizeFlag == null) {
            if (thisYear - studentEnrollVO.getYear() == 0) {
                desensitizeFlag = false;

            } else {
                desensitizeFlag = true;
            }

        }
        if (desensitizeFlag) {
            if (!EnrollStatusFormalEnum.lq.getType().equalsIgnoreCase(studentEnrollVO.getEnrollStatus())) {
                //录取不脱敏 其他都脱敏
                EduDesensitizeUtil.desensitizeStudentEnroll(studentEnrollVO);
            }
        }
        return studentEnrollVO;
    }


    /**
     * 设置核验材料
     *
     * @param enrollVerification
     * @param vo
     */
    private void setVerificationMaterial(EduStudentEnrollVerificationVO enrollVerification, EduStudentEnrollVO vo) {
        if (StringUtils.isBlank(enrollVerification.getVerificationType())) {
            return;
        }

        //房户一致list
        List<String> fhyzList = new ArrayList<>();
        fhyzList.add(VerificationTypeEnum.yzb.getType());
        fhyzList.add(VerificationTypeEnum.fwq.getType());
        fhyzList.add(VerificationTypeEnum.fhyz.getType());
        fhyzList.add(VerificationTypeEnum.fwqyzb.getType());
        //房产地址学区核验
        List<String> fcdzxqList = new ArrayList<>();
        fcdzxqList.add(VerificationTypeEnum.fwqfc.getType());
        fcdzxqList.add(VerificationTypeEnum.fcdz.getType());
        //户籍地址学区核验
        List<String> hjdzxqList = new ArrayList<>();
        hjdzxqList.add(VerificationTypeEnum.fwqhj.getType());
        hjdzxqList.add(VerificationTypeEnum.hjdz.getType());

        //接收材料信息
        List<EduMateria> materiaList = new ArrayList<>();
        //房户一致
        if (fhyzList.contains(enrollVerification.getVerificationType())) {
            //户籍地址
            if (StringUtils.isNotBlank(vo.getHouseholdAddress())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("学生户籍地址");
                materia.setMaterialTextValue(Convert.toDBC(vo.getHouseholdAddress()));
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
            //房产地址
            if (StringUtils.isNotBlank(vo.getHouseAdreess())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("报名房产地址");
                materia.setMaterialTextValue(Convert.toDBC(vo.getHouseAdreess()));
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
            //房产佐证材料
            if (StringUtils.isNotBlank(vo.getParam16())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("房产佐证材料");
                List<String> imageList = Arrays.asList(vo.getParam16().split(","));
                materia.setMaterialImgValue(imageList);
                materia.setMaterialType("img");
                materiaList.add(materia);

            }
            //户籍佐证材料
            if (StringUtils.isNotBlank(vo.getParam17())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("户口本");
                List<String> hkbImagList = Arrays.asList(vo.getParam17().split(","));
                materia.setMaterialImgValue(hkbImagList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }

        } else if (fcdzxqList.contains(enrollVerification.getVerificationType())) {
            //校验房产地址是否为学区
            if (StringUtils.isNotBlank(vo.getHouseAdreess())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("报名房产地址");
                materia.setMaterialTextValue(Convert.toDBC(vo.getHouseAdreess()));
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
        } else if (hjdzxqList.contains(enrollVerification.getVerificationType())) {
            //校验户籍地址是否为学区
            if (StringUtils.isNotBlank(vo.getHouseholdAddress())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("学生户籍地址");
                materia.setMaterialTextValue(Convert.toDBC(vo.getHouseholdAddress()));
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.qzgx.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            //校验亲子关系 param12:出生证  param15:结婚证  param17:户口本
            if (StringUtils.isNotBlank(vo.getParam12())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("出生证或结婚证");
                List<String> cszImagList = Arrays.asList(vo.getParam12().split(","));
                materia.setMaterialImgValue(cszImagList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
            if (StringUtils.isNotBlank(vo.getParam15())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("结婚证");
                List<String> jhzImagList = Arrays.asList(vo.getParam15().split(","));
                materia.setMaterialImgValue(jhzImagList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
            if (StringUtils.isNotBlank(vo.getParam17())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("户口本");
                List<String> hkbImagList = Arrays.asList(vo.getParam17().split(","));
                materia.setMaterialImgValue(hkbImagList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.fc.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            //房产
            if (StringUtils.isNotBlank(vo.getParam16())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("房产佐证材料");
                List<String> imageList = Arrays.asList(vo.getParam16().split(","));
                materia.setMaterialImgValue(imageList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
            if (StringUtils.isNotBlank(vo.getHouseAdreess())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("报名房产地址");
                materia.setMaterialTextValue(Convert.toDBC(vo.getHouseAdreess()));
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.hj.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            //户籍
            if (StringUtils.isNotBlank(vo.getParam17())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("户口本");
                List<String> hkbImagList = Arrays.asList(vo.getParam17().split(","));
                materia.setMaterialImgValue(hkbImagList);
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.sb.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            //社保
            if (StringUtils.isNotBlank(vo.getParam14())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("社保");
                materia.setMaterialImgValue(Arrays.asList(vo.getParam14().split(",")));
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.jzz.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            //居住证
            if (StringUtils.isNotBlank(vo.getParam13())) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("居住证");
                materia.setMaterialImgValue(Arrays.asList(vo.getParam13().split(",")));
                materia.setMaterialType("img");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.hyxz.getType().equalsIgnoreCase(enrollVerification.getVerificationType())) {
            if (!ObjectUtils.isEmpty(vo.getHjInfo())) {
                //取与户主关系
                if (StringUtils.isNotBlank(vo.getHjInfo().getHouseholder())) {
                    EduMateria materia = new EduMateria();
                    materia.setMaterialName("户主姓名");
                    materia.setMaterialTextValue(vo.getHjInfo().getHouseholder());
                    materia.setMaterialType("text");
                    materia.setIsMaximum(false);
                    materiaList.add(materia);
                }
                if (StringUtils.isNotBlank(vo.getHjInfo().getRelation())) {
                    EduMateria materia = new EduMateria();
                    materia.setMaterialName("与户主关系");
                    materia.setMaterialTextValue(vo.getHjInfo().getRelation());
                    materia.setMaterialType("text");
                    materia.setIsMaximum(false);
                    materiaList.add(materia);
                }
                //取迁入时间
                EduMateria materia = new EduMateria();
                materia.setMaterialName("学生户籍迁入时间");
                materia.setMaterialTextValue(vo.getHjInfo().getQysj());
                materia.setMaterialType("text");
                materia.setIsMaximum(false);
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.fcbl.getType().contains(enrollVerification.getVerificationType())) {
            //房产比例核验
            if (vo.getFcInfo() != null) {
                EduMateria materia = new EduMateria();
                materia.setMaterialName("产权占比");
                materia.setMaterialTextValue(vo.getFcInfo().getPrimarySchoolOne());
                materia.setMaterialType("text");
                materiaList.add(materia);
            }
        } else if (VerificationTypeEnum.yhwfsqnyf.getType().contains(enrollVerification.getVerificationType())) {
            //有户无房但市区内有房
            if (vo.getHouseList() != null) {
                int i = 1;
                for (EduHouseVO houseVO : vo.getHouseList()) {
                    EduMateria materia = new EduMateria();
                    materia.setMaterialName("房产" + i);
                    materia.setMaterialTextValue(houseVO.getAddress() + "[" + houseVO.getQlrName() + "]" + (houseVO.getRegisterDate() != null ? DateUtil.format(houseVO.getRegisterDate(), "yyyy-MM-dd") : "2016年之前"));
                    materia.setMaterialType("text");
                    materiaList.add(materia);
                    i++;
                }

            }
        }
        enrollVerification.setVerificationMateriaList(materiaList);
    }


    @Override
    public Boolean checkShLq(EnrollCheckShLqVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("年度不能为空");
        }
//        if (StringUtils.isBlank(vo.getOpType())) {
//            throw new AppException("操作类型不能为空");
//        }


        int year;
        year = eduHelper.thisYear();

        if (vo.getYear() < year) {
            return true;
        } else if (vo.getYear() > year) {
            return false;
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            throw new AppException("未找到用户所属行政区划,可能是未配置所属组织");
        }
        //EduEnrollPlan eduEnrollPlan = enrollPlanIntegration.getByYear(year);
        EduOperationCacheQueryVO cacheQueryVO = Convert.convert(EduOperationCacheQueryVO.class, vo);
        cacheQueryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(cacheQueryVO);
        if (eduOperationCacheVO.getOperation() == null) {
            throw new AppException(year + "年度招生计划参数不存在");
        }
        Long current = DateUtil.currentSeconds();
        if ("0".equals(vo.getOpType())) {
            //公办
            EduOperationCacheDetailVO detailVO = eduOperationCacheVO.getOperation().get("YW003");
            return detailVO.isFlag() || "2".equalsIgnoreCase(detailVO.getType());
        } else if ("1".equals(vo.getOpType())) {
            //民办1 PrivateDataStartDate
            EduOperationCacheDetailVO detailVO = eduOperationCacheVO.getOperation().get("YW007");
            return detailVO.isFlag() || "2".equalsIgnoreCase(detailVO.getType());
        } else if ("2".equals(vo.getOpType())) {
            //民转公 getMzgDataStartDate
            EduOperationCacheDetailVO detailVO = eduOperationCacheVO.getOperation().get("YW014");
            return detailVO.isFlag() || "2".equalsIgnoreCase(detailVO.getType());
        } else {
            return true;
        }

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0014", title = "义务教育报名一键退回到待审核", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0014",
            operationName = "义务教育报名一键退回到待审核",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void backAuth(EduStudentEnrollKeyVO vo) {
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被退回");
        }
        if (EnrollStatusFormalEnum.hy.getType().equalsIgnoreCase(old.getEnrollStatus()) && AuthStatusEnum.NODO.getType().equals(old.getAuthStatus())) {
            throw new AppException("待核验不能退回");
        }
        if (EnrollStatusFormalEnum.dsh.getType().equalsIgnoreCase(old.getEnrollStatus()) && AuthStatusEnum.NODO.getType().equals(old.getAuthStatus())) {
            throw new AppException("报名数据已是待审核状态");
        }
        if (EnrollStatusFormalEnum.xtblq.getType().equalsIgnoreCase(old.getEnrollStatus())) {
            throw new AppException("无效数据不能退回到上一步");
        }

        if (old.getSerialNum() != null) {
            throw new AppException("已摇号数据不能退回到待审核");
        }
        if (StringUtils.isBlank(old.getAreaCode())) {
            old.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduOperationCacheQueryVO cacheQueryVO = Convert.convert(EduOperationCacheQueryVO.class, old);
        cacheQueryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(cacheQueryVO);
        if (eduOperationCacheVO.getOperation() == null) {
            throw new AppException(old.getYear() + "年度招生计划参数不存在");
        }
        Long current = DateUtil.currentSeconds();
        if ("0".equals(old.getSchoolNature())) {
            // 公办
            if (eduOperationCacheVO.getOperation().get("YW003") != null) {
                if (!eduOperationCacheVO.getOperation().get("YW003").isFlag()) {
                    throw new AppException("只有公办审核期间才能退回");
                }
            } else {
                throw new AppException("公办审核录取时间未配置，请核对");
            }


        } else if ("1".equals(old.getSchoolNature())) {
            // 民办
            if (eduOperationCacheVO.getOperation().get("YW007") != null) {
                if (!eduOperationCacheVO.getOperation().get("YW007").isFlag()) {
                    throw new AppException("只有在民办审核期间才能退回");
                }
            } else {
                throw new AppException("民办审核期未配置，请核对");
            }

        } else if ("2".equals(old.getSchoolNature())) {
            // 民转公
            if (eduOperationCacheVO.getOperation().get("YW014") != null) {
                if (!eduOperationCacheVO.getOperation().get("YW014").isFlag()) {
                    throw new AppException("只有在民转公审核期间才能退回");
                }
            } else {
                throw new AppException("民转公审核期未配置，请核对");
            }
        }

        if (EnrollStatusFormalEnum.ywblq.getType().equals(old.getEnrollStatus()) || EnrollStatusFormalEnum.xtblq.getType().equals(old.getEnrollStatus())
                || EnrollStatusFormalEnum.hybtg.getType().equals(old.getEnrollStatus()) || EnrollStatusFormalEnum.wpz.getType().equals(old.getEnrollStatus())
                || EnrollStatusFormalEnum.tc.getType().equals(old.getEnrollStatus())) {
            //从不录取退回到待审核，需要判断其他学校是否审核录取
            List<String> enrollStatusList = new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.bh.getType());
            QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnroll::getYear, old.getYear())
                    .eq(EduStudentEnroll::getIdcard, old.getIdcard())
                    .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                    .ne(EduStudentEnroll::getStudentEnrollId, old.getStudentEnrollId());
            if (eduStudentEnrollService.count(queryWrapper) > 0) {
                throw new AppException("因其他学校审核中或录取，这个学校不能从不录取退回到待审核");
            }
        }

        //如果是录取状态，退回一步需要删除录取数据  复审通过退回删除审核数据
        if (EnrollStatusFormalEnum.lq.getType().equals(old.getEnrollStatus())) {
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("3");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        } else if (EnrollStatusFormalEnum.fs.getType().equals(old.getEnrollStatus())) {
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("2");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        }


        //todo 根据审核表的情况，判断退回到哪一步
        if (EnrollStatusFormalEnum.lq.getType().equalsIgnoreCase(old.getEnrollStatus()) || EnrollStatusFormalEnum.wpz.getType().equalsIgnoreCase(old.getEnrollStatus()) || EnrollStatusFormalEnum.tc.getType().equalsIgnoreCase(old.getEnrollStatus())) {
            //录取状态，退回到待录取
            old.setAdmitFlag(null);
            old.setAdmitTime(null);
            old.setAdmitRemarks(null);
            old.setEnrollStatus(EnrollStatusFormalEnum.fs.getType());

        } else {

            LambdaQueryWrapper<EduStudentEnrollReview> checkQuery = new QueryWrapper<EduStudentEnrollReview>()
                    .lambda().select(EduStudentEnrollReview::getStudentEnrollReviewId, EduStudentEnrollReview::getAuditType, EduStudentEnrollReview::getAuthStatus).eq(EduStudentEnrollReview::getStudentEnrollId, vo.getStudentEnrollId())
                    .orderByDesc(EduStudentEnrollReview::getCreateTime);
            List<EduStudentEnrollReview> enrollReviewList = eduStudentEnrollReviewService.list(checkQuery);
            if (CollectionUtils.isEmpty(enrollReviewList)) {
                throw new AppException("没有审核数据，不能退回");
            }
            EduStudentEnrollReview review = enrollReviewList.get(0);
            if (EnrollReviewStatusFormalEnum.fs.getType().equalsIgnoreCase(review.getAuditType())) {
                //最新状态是复审
                if (EnrollStatusFormalEnum.ywblq.getType().equalsIgnoreCase(old.getEnrollStatus())) {
                    if (AuthStatusEnum.YES.getType().equalsIgnoreCase(review.getAuthStatus())) {
                        //复审通过业务不予录取退回到待录取
                        old.setAdmitFlag(null);
                        old.setAdmitTime(null);
                        old.setAdmitRemarks(null);
                        old.setEnrollStatus(EnrollStatusFormalEnum.fs.getType());

                    } else {
                        //复审不通过通过业务不予录取退回到资料审核通过
                        old.setAuthStatus(AuthStatusEnum.NODO.getType());
                        old.setAuthRemarks(null);
                        old.setAuthTime(null);
                        old.setAuthUserId(null);
                        old.setAdmitFlag(null);
                        old.setAdmitTime(null);
                        old.setAdmitRemarks(null);
                        old.setEnrollStatus(EnrollStatusFormalEnum.dlq.getType());
                        eduStudentEnrollReviewService.removeById(review.getStudentEnrollReviewId());

                    }
                } else if (EnrollStatusFormalEnum.fs.getType().equalsIgnoreCase(old.getEnrollStatus())) {
                    //复审通过状态退回到待复审
                    old.setAuthStatus(AuthStatusEnum.NODO.getType());
                    old.setAuthRemarks(null);
                    old.setAuthTime(null);
                    old.setAuthUserId(null);
                    old.setAdmitFlag(null);
                    old.setAdmitTime(null);
                    old.setAdmitRemarks(null);
                    old.setEnrollStatus(EnrollStatusFormalEnum.dlq.getType());
                    eduStudentEnrollReviewService.removeById(review.getStudentEnrollReviewId());
                } else {
                    throw new AppException("审核数据异常，请联系系统管理员");
                }
            }
            if (EnrollReviewStatusFormalEnum.cs.getType().equalsIgnoreCase(review.getAuditType())) {
                //最新状态是初审
                if (EnrollStatusFormalEnum.ywblq.getType().equalsIgnoreCase(old.getEnrollStatus())) {
                    old.setAuthStatus(AuthStatusEnum.NODO.getType());
                    old.setAuthRemarks(null);
                    old.setAuthTime(null);
                    old.setAuthUserId(null);
                    old.setAdmitFlag(null);
                    old.setAdmitTime(null);
                    old.setAdmitRemarks(null);
                    old.setAspirationType("0");
                    old.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                    eduStudentEnrollReviewService.removeById(review.getStudentEnrollReviewId());
                } else if (EnrollStatusFormalEnum.dlq.getType().equalsIgnoreCase(old.getEnrollStatus())) {
                    old.setAuthStatus(AuthStatusEnum.NODO.getType());
                    old.setAuthRemarks(null);
                    old.setAuthTime(null);
                    old.setAuthUserId(null);
                    old.setAdmitFlag(null);
                    old.setAdmitTime(null);
                    old.setAdmitRemarks(null);
                    old.setAspirationType("0");
                    if ("2".equalsIgnoreCase(old.getIcertificatioFlag())) {
                        old.setEnrollStatus(EnrollStatusFormalEnum.hy.getType());
                        old.setIcertificatioFlag(VerificationAuthStatusEnum.dhy.getType());
                    } else {
                        old.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                    }
                    eduStudentEnrollReviewService.removeById(review.getStudentEnrollReviewId());
                } else if (EnrollStatusFormalEnum.hybtg.getType().equalsIgnoreCase(old.getEnrollStatus())) {
                    old.setAuthStatus(AuthStatusEnum.NODO.getType());
                    old.setAuthRemarks(null);
                    old.setAuthTime(null);
                    old.setAuthUserId(null);
                    old.setAdmitFlag(null);
                    old.setAdmitTime(null);
                    old.setAdmitRemarks(null);
                    old.setAspirationType("0");
                    old.setEnrollStatus(EnrollStatusFormalEnum.hy.getType());
                    old.setIcertificatioFlag(VerificationAuthStatusEnum.dhy.getType());
                    eduStudentEnrollReviewService.removeById(review.getStudentEnrollReviewId());
                } else {
                    throw new AppException("审核数据异常，请联系系统管理员");
                }
            }
        }


        eduStudentEnrollService.updateById(old);
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getMotherIdcard());

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0064", title = "义务教育报名撤销（民办公办单独）", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0064",
            operationName = "义务教育报名撤销（民办公办单独）",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywApplyBackDg(EduStudentEnrollKeyVO vo) {
        EduStudentEnroll studentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (!StringUtils.equals(studentEnroll.getAuthStatus(), AuthStatusEnum.NODO.getType())) {
            throw new AppException("当前人员已审核，不允许退回");
        }
        eduStudentEnrollService.removeById(vo.getStudentEnrollId());
        LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(EduStudentEnrollPre::getStudentEnrollPreId).eq(EduStudentEnrollPre::getYear, studentEnroll.getYear())
                .eq(EduStudentEnrollPre::getIdcard, studentEnroll.getIdcard());
        List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(preList)) {
            for (EduStudentEnrollPre pre : preList) {
                eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
            }
        }

        //清除同步表报名数据
        //复审不通过，删除录取表，删除审核表 删除报名表 同步数据
        EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
        deleteQueryVO.setIdcard(studentEnroll.getIdcard());
        deleteQueryVO.setApplyCountyCode(studentEnroll.getAreaCode());
        try {
            deleteQueryVO.setDeleteType("3");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            deleteQueryVO.setDeleteType("2");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            deleteQueryVO.setDeleteType("1");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
        } catch (AppException e) {
            throw new AppException(e.getMessage());
        }
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getMotherIdcard());
        String bmKey = EduCache.EDU_ENROLL_ZS + studentEnroll.getIdcard();
        redisHelper.del(bmKey);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0063", title = "家长端义务教育报名撤销", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0063",
            operationName = "家长端义务教育报名撤销",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywApplyBackApp(EduStudentEnrollKeyVO vo) {

        EduStudentEnroll studentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (!StringUtils.equals(studentEnroll.getAuthStatus(), AuthStatusEnum.NODO.getType())) {
            throw new AppException("当前人员已审核，不允许退回");
        }
        if (!SessionUtil.getUserId().equalsIgnoreCase(studentEnroll.getCreateName())) {
            throw new AppException("只能通过报名账号才能进行撤销");
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(studentEnroll.getAreaCode());
        queryVO.setYear(studentEnroll.getYear());
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO bmOperation = operation.get("YW002");//第一批
        EduOperationCacheDetailVO bbOperation = operation.get("YW022");//第二批
        EduOperationCacheDetailVO qbOperation = operation.get("YW010");//第三批
        EduOperationCacheDetailVO bmxxOperation = operation.get("YW066");//第一批小学报名业务期
        EduOperationCacheDetailVO bmczOperation = operation.get("YW067");//第一批初中报名业务期
        EduOperationCacheDetailVO bbxxOperation = operation.get("YW068");//第二批小学报名业务期
        EduOperationCacheDetailVO bbczOperation = operation.get("YW069");//第二批初中报名业务期
        EduOperationCacheDetailVO qbxxOperation = operation.get("YW070");//第三批小学报名业务期
        EduOperationCacheDetailVO qbczOperation = operation.get("YW071");//第三批初中报名业务期
        EduOperationCacheDetailVO bbTwoOperation = operation.get("YW072");//第二批第二次
        EduOperationCacheDetailVO bbTwoXxOperation = operation.get("YW073");//第二批小学第二次
        EduOperationCacheDetailVO bbTwoCzOperation = operation.get("YW074");//第二批初中第二次

        //判断是否报名业务期
        boolean bmFlag = bmOperation == null ? false : bmOperation.isFlag();
        boolean bmxxFlag = bmxxOperation == null ? false : bmxxOperation.isFlag();
        boolean bmczFlag = bmczOperation == null ? false : bmczOperation.isFlag();
        //判断是否补报业务期
        boolean bbFlag = bbOperation == null ? false : bbOperation.isFlag();
        boolean bbxxFlag = bbxxOperation == null ? false : bbxxOperation.isFlag();
        boolean bbczFlag = bbczOperation == null ? false : bbczOperation.isFlag();
        //第二批次第二次
        boolean bbTwoFlag = bbTwoOperation == null ? false : bbTwoOperation.isFlag();
        boolean bbxxTwoFlag = bbTwoXxOperation == null ? false : bbTwoXxOperation.isFlag();
        boolean bbczTwoFlag = bbTwoCzOperation == null ? false : bbTwoCzOperation.isFlag();

        //判断是否空额抢报业务期
        boolean qbFlag = qbOperation == null ? false : qbOperation.isFlag();
        boolean qbxxFlag = qbxxOperation == null ? false : qbxxOperation.isFlag();
        boolean qbczFlag = qbczOperation == null ? false : qbczOperation.isFlag();
        String schoolCategory = studentEnroll.getSchoolCategory();
        if (!bmFlag && !bbFlag && !qbFlag&&!bbTwoFlag) {
            throw new AppException("本批次报名时间已过不能撤销");
        } else {
            if (bmFlag) {
                if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bmxxFlag) {
                        throw new AppException("本批次小学报名时间已过不能撤销");
                    }
                } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bmczFlag) {
                        throw new AppException("本批次初中报名时间已过不能撤销");
                    }
                }
            }
            if (bbFlag) {
                if (!bbxxTwoFlag&&SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bbxxFlag) {
                        throw new AppException("本批次小学报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                        if(studentEnroll.getEnrollNum()!=2){
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                }
                if (!bbczTwoFlag&&SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bbczFlag) {
                        throw new AppException("本批次初中报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                        if(studentEnroll.getEnrollNum()!=2){
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                }
            }
            if (bbTwoFlag) {
                if (!bbxxFlag&&SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bbxxTwoFlag) {
                        throw new AppException("本批次小学报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                        if(studentEnroll.getEnrollNum()!=3){
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                }
                if (!bbczFlag&&SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!bbczTwoFlag) {
                        throw new AppException("本批次初中报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                        if(studentEnroll.getEnrollNum()!=3){
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                }
            }
            if (qbFlag) {
                if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!qbxxFlag) {
                        throw new AppException("本批次小学报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getSpareRegisterFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(schoolCategory)) {
                    if (!qbczFlag) {
                        throw new AppException("本批次初中报名时间已过不能撤销");
                    } else {
                        if (!"1".equalsIgnoreCase(studentEnroll.getSpareRegisterFlag())) {
                            throw new AppException("本批次报名时间已过不能撤销");
                        }
                    }
                }
            }
        }
        long curTime = DateUtil.currentSeconds();

        if (bbFlag && !"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
            throw new AppException("本批次报名时间已过不能撤销");
        }
        if (bbTwoFlag && !"1".equalsIgnoreCase(studentEnroll.getBbFlag())) {
            throw new AppException("本批次报名时间已过不能撤销");
        }

        if (qbFlag && !"1".equalsIgnoreCase(studentEnroll.getSpareRegisterFlag())) {
            throw new AppException("本批次报名时间已过不能撤销");
        }
        eduStudentEnrollService.removeById(vo.getStudentEnrollId());
        LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(EduStudentEnrollPre::getStudentEnrollPreId).eq(EduStudentEnrollPre::getYear, studentEnroll.getYear())
                .eq(EduStudentEnrollPre::getIdcard, studentEnroll.getIdcard());
        List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(preList)) {
            for (EduStudentEnrollPre pre : preList) {
                eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
            }
        }

        //撤销报名，需要删除同步报名表数据
        EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
        deleteQueryVO.setIdcard(studentEnroll.getIdcard());
        deleteQueryVO.setApplyCountyCode(studentEnroll.getAreaCode());
        deleteQueryVO.setDeleteType("1");
        try {
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
        } catch (AppException e) {
            throw new AppException(e.getMessage());
        }
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(studentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(studentEnroll.getMotherIdcard());
        String bmKey = EduCache.EDU_ENROLL_ZS + studentEnroll.getIdcard();
        redisHelper.del(bmKey);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0016", title = "义务教育报名修改报名状态", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0016",
            operationName = "义务教育报名修改报名状态",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void updateEnrollStatus(UpdateEnrollStatusVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getEnrollStatus())) {
            throw new AppException("报名状态不能为空");
        }
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被退回");
        }
        if (old.getEnrollStatus().equals(vo.getEnrollStatus())) {
            throw new AppException("报名状态和数据库中一致，请刷新后再操作");
        }
        old.setEnrollStatus(vo.getEnrollStatus());
        if (StringUtils.isNotBlank(old.getAuthStatus())) {
            old.setAuthStatus(AuthStatusEnum.NO.getType());
        }
        if (StringUtils.isNotBlank(old.getAdmitFlag())) {
            old.setAdmitFlag("0");
        }
        eduStudentEnrollService.updateById(old);
        //设置报名无效删除录取消息发送表
        LambdaQueryWrapper<EduSendMessage> queryWrapper = new QueryWrapper<EduSendMessage>().lambda()
                .eq(EduSendMessage::getStudentEnrollId, old.getStudentEnrollId());
        List<EduSendMessage> eduSendMessageList = eduSendMessageService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(eduSendMessageList)){
            for (EduSendMessage sendMessage:eduSendMessageList){
                eduSendMessageService.removeById(sendMessage.getMessageId());
            }
        }
        //删除录取表，删除审核表 删除报名表
        EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
        deleteQueryVO.setIdcard(old.getIdcard());
        deleteQueryVO.setApplyCountyCode(old.getAreaCode());
        try {
            deleteQueryVO.setDeleteType("3");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            deleteQueryVO.setDeleteType("2");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            deleteQueryVO.setDeleteType("1");
            syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
        } catch (AppException e) {
            throw new AppException(e.getMessage());
        }
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getMotherIdcard());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0017", title = "义务教育报名人员查询(根据身份证)", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getYwApplyInfoByIdcard(EduStudentEnrollQueryVO vo) {
        if (StringUtils.isBlank(vo.getIdcard())) {
            throw new AppException("身份证不能为空");
        }
        int year = eduHelper.thisYear();

        String schoolId = vo.getSchoolId();
        if (StringUtils.isBlank(schoolId)) {
            schoolId = SessionUtil.getSessionInfo().getOrgId();
        }
        QueryWrapper<EduStudentEnroll> studentEnrollQueryWrapper = new QueryWrapper<>();
        studentEnrollQueryWrapper
                .lambda()
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dsh.getType())
                .eq(vo.getYear() != null, EduStudentEnroll::getYear, year)
                .eq(
                        StringUtils.isNotBlank(vo.getIdcard()),
                        EduStudentEnroll::getIdcard,
                        vo.getIdcard())
                .eq(EduStudentEnroll::getSchoolId, schoolId);
        List<EduStudentEnroll> list = eduStudentEnrollService.list(studentEnrollQueryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentEnroll> pageInfo = new PageInfo<>(list);
        List<EduStudentEnrollVO> resultList = Convert.toList(EduStudentEnrollVO.class, list);
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0018", title = "义务教育报名信息导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void exportYwApplyInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setDataexportYwApplyInfo(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }

    }

    private void setDataexportYwApplyInfo(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentEnrollQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            vo.setDesensitizeFlag(false);
            PageInfo<EduStudentEnrollVO> pageInfo = getYwApplyList(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Object> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentEnrollVO eduStudentEnrollVO : pageInfo.getList()) {
                    list.add(eduStudentEnrollVO);
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeBean(excelWriter, list);
            } else {
                excelCommonHelper.writeBean(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setDataexportYwApplyInfo(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    @Override
    public PageInfo<EduStudentEnrollVO> getYwApplyList(EduStudentEnrollQueryVO vo) {
        if (StringUtils.isBlank(vo.getSchoolId())) {
            vo.setSchoolId(SessionUtil.getOrgId());
        }
        if (vo.getYear() == null) {
            throw new AppException("查询年度不能空");
        }
        if (BoolEnum.TRUE.getType().equals(vo.getXxllFlag())) {
            vo.setSource("6");
        }
        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            String orderBy = "";
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    orderBy = orderBy + ",";
                    if (orderVO.getProperty().equals("registerDate")) {
                        orderBy = orderBy + "a.";
                    } else if (orderVO.getProperty().equals("qysj")) {
                        orderBy = orderBy + "a.";
                    } else {
                        orderBy = orderBy + "a.";
                    }
                    orderBy = orderBy + StrUtil.toUnderlineCase(orderVO.getProperty()) + " " + orderVO.getOrder();
                }
            }
            vo.setOrderBy(orderBy);

        }
        // 开启分页
        if (vo.getPageNum() != null && vo.getPageSize() != null) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        }
        List<EduStudentEnrollVO> list = eduStudentEnrollService.getYwApplyList(vo);

        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        Boolean desensitizeFlag = vo.getDesensitizeFlag();

        // 不为空则获取分页结果
        PageInfo<EduStudentEnrollVO> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollVO> resultList = pageInfo.getList();
        dictHelper.valueToName(resultList, Arrays.asList(EduYwEnrollDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getAreaCode, a -> a, (k1, k2) -> k1));
        boolean flag = false;
        Map<String, EduStudentEnroll> map = new HashMap<>();


        //获取报名id
        List<String> enrollIdList = resultList.stream().map(EduStudentEnrollVO::getStudentEnrollId).distinct().collect(Collectors.toList());
        List<String> authStatusList = new ArrayList<>();
        authStatusList.add(AuthStatusEnum.NODO.getType());
        authStatusList.add(AuthStatusEnum.YES.getType());
        QueryWrapper<EduStudentEnrollInvalid> invalidQueryWrapper = new QueryWrapper<>();
        invalidQueryWrapper.lambda()
                .select(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus)
                .in(EduStudentEnrollInvalid::getStudentEnrollId, enrollIdList)
                .in(EduStudentEnrollInvalid::getAuthStatus, authStatusList);
        List<EduStudentEnrollInvalid> invalidList = eduStudentEnrollInvalidService.list(invalidQueryWrapper);
        Map<String, String> collectMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(invalidList)) {
            collectMap = invalidList.stream().collect(Collectors.toMap(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus));
        }
        //获取学生证件号码
        List<String> idcardList = resultList.stream().map(EduStudentEnrollVO::getIdcard).distinct().collect(Collectors.toList());
        //查询户籍信息
        EduSchoolVO eduSchoolVO = eduSchoolService.getDetail(vo.getSchoolId());
        QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
        householdQueryWrapper.lambda().in(EduHousehold::getIdcard, idcardList)
                .eq(EduHousehold::getAreaCode, eduSchoolVO.getAreaCode())
                .eq(EduHousehold::getYear, vo.getYear())
                .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType());
        List<EduHousehold> householdList = eduHouseholdService.list(householdQueryWrapper);
        Map<String, String> householdMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(householdList)) {
            householdMap = householdList.stream().collect(Collectors.toMap(EduHousehold::getIdcard, EduHousehold::getAddress, (k1, k2) -> k1));
        }
        Integer year = eduHelper.thisYear();
        if (desensitizeFlag == null) {
            desensitizeFlag = true;
        }
        for (EduStudentEnrollVO studentEnroll : resultList) {
            if (SchoolNatureEnum.mzg.getType().equalsIgnoreCase(eduSchoolVO.getSchoolNature())) {
                studentEnroll.setHasHousehold(false);
                studentEnroll.setHasHouse(false);
                EduStudentEnroll enroll = map.get(studentEnroll.getIdcard());
                if (enroll != null) {
                    if ("A".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(true);
                        studentEnroll.setRegisterDate(null);
                    } else if ("B".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(false);
                        studentEnroll.setRegisterDate(null);
                    } else if ("C".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(false);
                        studentEnroll.setHasHouse(true);
                        if (householdMap.containsKey(studentEnroll.getIdcard())) {
                            studentEnroll.setHasHousehold(true);
                            if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                                studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                            }
                        } else {
                            studentEnroll.setHasHousehold(false);
                        }
                    } else if ("特殊户口".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(false);
                    } else {
                        if (householdMap.containsKey(studentEnroll.getIdcard())) {
                            studentEnroll.setHasHousehold(true);
                            if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                                studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                            }
                        } else {
                            studentEnroll.setHasHousehold(false);
                        }

                    }
                }
            } else if (SchoolNatureEnum.mb.getType().equalsIgnoreCase(eduSchoolVO.getSchoolNature())) {
                if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                    studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                }
                if (!BoolEnum.TRUE.getType().equalsIgnoreCase(studentEnroll.getFollowingFlag())) {
                    if (householdMap.containsKey(studentEnroll.getIdcard())) {
                        studentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                    }
                }
            }
            if ("社保".equalsIgnoreCase(studentEnroll.getConfigName())) {
                ArrayList<String> fmIdcardList = new ArrayList<>();
                if (StringUtils.isNotBlank(studentEnroll.getFatherIdcard())) {
                    fmIdcardList.add(studentEnroll.getFatherIdcard());
                }
                if (StringUtils.isNotBlank(studentEnroll.getMotherIdcard())) {
                    fmIdcardList.add(studentEnroll.getMotherIdcard());
                }
                LambdaQueryWrapper<EduSocialSecurity> queryWrapper = new QueryWrapper<EduSocialSecurity>().lambda()
                        .select(EduSocialSecurity::getAac002, EduSocialSecurity::getAac003, EduSocialSecurity::getTotal,
                                EduSocialSecurity::getAab301, EduSocialSecurity::getTotalBclx,
                                EduSocialSecurity::getAab301, EduSocialSecurity::getContinuityFlag)
                        .in(EduSocialSecurity::getAac002, fmIdcardList)
                        .eq(EduSocialSecurity::getAae140, "110")
                        .eq(EduSocialSecurity::getAac008, "1")
                        .eq(EduSocialSecurity::getYear, studentEnroll.getYear());
                List<EduSocialSecurity> securityList = eduSocialSecurityService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(securityList)) {
                    int count = 1;
                    HashMap<String, String> areaCodeMap = new HashMap<>();
                    areaCodeMap.put("330799", "市本级");
                    areaCodeMap.put("330702", "婺城区");
                    areaCodeMap.put("330703", "金东区");
                    areaCodeMap.put("330704", "开发区");
                    for (EduSocialSecurity security : securityList) {
                        if (count == 1) {
                            studentEnroll.setGuardianOne(security.getAac003());
                            studentEnroll.setIsContinuityOne(security.getContinuityFlag().equals("1") ? "是" : "否");
                            studentEnroll.setTotalOne(security.getTotal());
                            studentEnroll.setDqTotalOne(security.getTotalBclx());
                            if (StringUtils.isNotBlank(areaCodeMap.get(security.getAab301()))) {
                                studentEnroll.setCbAreaCodeOne(areaCodeMap.get(security.getAab301()));
                            } else {
                                studentEnroll.setCbAreaCodeOne("其他");
                            }
                        }
                        if (count == 2) {
                            studentEnroll.setGuardianTwo(security.getAac003());
                            studentEnroll.setIsContinuityTwo(security.getContinuityFlag().equals("1") ? "是" : "否");
                            studentEnroll.setTotalTwo(security.getTotal());
                            studentEnroll.setDqTotalTwo(security.getTotalBclx());
                            if (StringUtils.isNotBlank(areaCodeMap.get(security.getAab301()))) {
                                studentEnroll.setCbAreaCodeTwo(areaCodeMap.get(security.getAab301()));
                            } else {
                                studentEnroll.setCbAreaCodeTwo("其他");
                            }
                        }
                        count += 1;
                    }

                }
            }
            studentEnroll.setDelStatus(collectMap.get(studentEnroll.getStudentEnrollId()));

            if (!flag && EnrollStatusFormalEnum.dlq.getType().equals(studentEnroll.getEnrollStatus())) {
                flag = true;
                studentEnroll.setFirstFlag(true);
            } else {
                studentEnroll.setFirstFlag(false);
            }
            //设置街道
            if (!ObjectUtils.isEmpty(areaMap.get(studentEnroll.getStreet()))) {
                studentEnroll.setStreetName(areaMap.get(studentEnroll.getStreet()).getAreaName());
            }
            if (StringUtils.isBlank(studentEnroll.getAdmitFlag())) {
                studentEnroll.setAdmitFlag("2");
                studentEnroll.setAdmitFlagName("待录取");
            } else {
                if (BoolEnum.TRUE.getType().equals(studentEnroll.getAdmitFlag())) {
                    studentEnroll.setAdmitFlagName("已录取");
                } else {
                    studentEnroll.setAdmitFlagName("不予录取");
                }
            }
            if (BoolEnum.TRUE.getType().equals(studentEnroll.getSpecialFlag())) {
                studentEnroll.setSpecialFlagName("是");
            } else {
                studentEnroll.setSpecialFlagName("否");
            }
            if (StringUtils.isNotBlank(studentEnroll.getEnrollStatus())) {
                EnrollStatusFormalEnum formalEnum = EnrollStatusFormalEnum.getByType(studentEnroll.getEnrollStatus());
                studentEnroll.setEnrollStatusName(formalEnum == null ? "未知状态" : formalEnum.getName());
            } else {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                studentEnroll.setEnrollStatusName(EnrollStatusFormalEnum.dsh.getName());
            }

            if (StringUtils.isBlank(studentEnroll.getConfigNameAlias())) {
                studentEnroll.setConfigNameAlias(studentEnroll.getConfigName());
            }
            if (desensitizeFlag) {
                if (!EnrollStatusFormalEnum.lq.getType().equalsIgnoreCase(studentEnroll.getEnrollStatus())) {
                    //录取不脱敏 其他都脱敏
                    EduDesensitizeUtil.desensitizeStudentEnroll(studentEnroll);
                }
            }
        }

        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0020", title = "义务教育报名人数信息查询", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public StudentEnrollCntVO queryBmCnt(EduStudentEnrollQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }
        if (vo.getYear() == null) {
            throw new AppException("请输入查询年份");
        }

        StudentEnrollCntVO retVO = new StudentEnrollCntVO();
        Integer zrs = 0;
        Integer dsh = 0;
        Integer dlq = 0;
        Integer ylq = 0;
        Integer dhy = 0;
        Integer dfs = 0;


        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.wpz.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.ywblq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.hybtg.getType());

        queryWrapper.lambda().select(EduStudentEnroll::getEnrollStatus)
                .eq(StringUtils.isNotBlank(vo.getSchoolId()), EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnroll::getYear, vo.getYear())
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(StringUtils.isNotBlank(vo.getConfigName()), EduStudentEnroll::getConfigTypeName, vo.getConfigName())
                .eq(StringUtils.isNotBlank(vo.getFollowingFlag()), EduStudentEnroll::getFollowingFlag, vo.getFollowingFlag());
        List<EduStudentEnroll> list = eduStudentEnrollService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            for (EduStudentEnroll enroll : list) {
                if (EnrollStatusFormalEnum.lq.getType().equals(enroll.getEnrollStatus())) {
                    ylq = ylq + 1;
                }
            }
        }
        queryWrapper.lambda().eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType());
        list = eduStudentEnrollService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            zrs = list.size();
            for (EduStudentEnroll enroll : list) {
                if (EnrollStatusFormalEnum.dsh.getType().equals(enroll.getEnrollStatus())) {
                    dsh = dsh + 1;
                }
                if (EnrollStatusFormalEnum.hy.getType().equals(enroll.getEnrollStatus())) {
                    dhy = dhy + 1;
                }
                if (EnrollStatusFormalEnum.dlq.getType().equals(enroll.getEnrollStatus())) {
                    dfs = dfs + 1;
                }
                if (EnrollStatusFormalEnum.fs.getType().equals(enroll.getEnrollStatus())) {
                    dlq = dlq + 1;
                }
            }

        }

        retVO.setZrs(zrs);
        retVO.setDsh(dsh);
        retVO.setDlq(dlq);
        retVO.setDhy(dhy);
        retVO.setYlq(ylq);
        retVO.setDfh(dfs);
        List<EduSchoolConfig> configList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getIsGly())) {
            vo.setIsGly(false);
        }
        if (!vo.getIsGly()) {
            QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
            configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                    .eq(StringUtils.isNotBlank(vo.getSchoolId()), EduSchoolConfig::getSchoolId, vo.getSchoolId())
                    .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduSchoolConfig::getYear, vo.getYear())
                    .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduSchoolConfig::getConfigTypeName, vo.getConfigTypeName());
            configList = eduSchoolConfigService.list(configQueryWrapper);
        }
        int jhs = 0;
        if (!CollectionUtils.isEmpty(configList)) {
            for (EduSchoolConfig config : configList) {
                Integer count = config.getEnrolment() == null ? 0 : config.getEnrolment();
                jhs = jhs + count;
            }
        }
        int serialNumEnd = 0;
        if (StringUtils.isNotBlank(vo.getConfigTypeName())) {
            if (!CollectionUtils.isEmpty(configList)) {
                serialNumEnd = configList.get(0).getSerialNumEnd() == null ? 0 : configList.get(0).getSerialNumEnd();
            }
        }
        retVO.setSerialNumEnd(serialNumEnd);
        retVO.setJhs(jhs);
        if (jhs - ylq > 0) {
            retVO.setLqFlag(true);
        } else {
            retVO.setLqFlag(false);
        }
        return retVO;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0021", title = "义务教育民转公批量录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0021",
            operationName = "义务教育民转公批量录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void batchMzgAdmit(StudentEnrollBatchVO vo) {
        batchAdmit(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0022", title = "义务教育民办批量录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0022",
            operationName = "义务教育民办批量录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void batchAdmit(StudentEnrollBatchVO vo) {
        String schoolId = vo.getSchoolId();
        if (StringUtils.isBlank(schoolId)) {
            schoolId = SessionUtil.getSessionInfo().getOrgId();
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        String reidsKey = batchAdmitKey + vo.getSchoolId();
        if (redisHelper.hasKey(reidsKey)) {
            throw new AppException("系统正在执行中，请稍后！");
        }
        if (StringUtils.isBlank(vo.getConfigTypeName())) {
            throw new AppException("报名类别不能为空");
        }
        int year = 0;
        year = eduHelper.thisYear();
        QueryWrapper<EduStudentEnroll> studentEnrollQueryWrapper = new QueryWrapper<>();
        studentEnrollQueryWrapper.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnroll::getYear, year)
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType())
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType());
        List<EduStudentEnroll> studentEnrollList =
                eduStudentEnrollService.list(studentEnrollQueryWrapper);
        if (CollectionUtils.isEmpty(studentEnrollList)) {
            throw new AppException("没有需要录取的人员");
        }
        studentEnrollQueryWrapper.lambda().isNotNull(EduStudentEnroll::getSerialNum);
        if (eduStudentEnrollService.count(studentEnrollQueryWrapper) > 0) {
            throw new AppException("摇号的数据，只能单个录取");
        }
        QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                .eq(EduSchoolConfig::getSchoolId, schoolId)
                .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                .eq(EduSchoolConfig::getYear, year)
                .eq(EduSchoolConfig::getConfigTypeName, vo.getConfigTypeName());
        EduSchoolConfig eduSchoolConfig = eduSchoolConfigService.getOne(configQueryWrapper, false);
        if (eduSchoolConfig == null) {
            throw new AppException("该报名类别未配置招生计划");
        }

        //摇号序号截止
        Integer serialNumEnd = eduSchoolConfig.getSerialNumEnd() == null ? 0 : eduSchoolConfig.getSerialNumEnd();
        //招生计划人数
        Integer enrolment = eduSchoolConfig.getEnrolment() == null ? 0 : eduSchoolConfig.getEnrolment();

        QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
        brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, year)
                .eq(EduEnrollmenBrochure::getSchoolId, schoolId);
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }
        EduOperationCacheQueryVO queryOpVO = new EduOperationCacheQueryVO();
        queryOpVO.setClassify("2");
        queryOpVO.setAreaCode(eduEnrollmenBrochure.getAreaCode());
        queryOpVO.setYear(eduEnrollmenBrochure.getYear());
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryOpVO);
        if (eduOperationCacheVO == null) {
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("学校招生已停止，不能录取");
        }
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO detailVO = operation.get("YW009");
        if (!detailVO.isFlag()) {
            throw new AppException("未在第一志愿招生录取操作期内，请联系基教科处理");
        }

        //已录取人数
        QueryWrapper<EduStudentEnroll> lqQuery = new QueryWrapper<>();
        lqQuery.lambda().eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getAdmitFlag, BoolEnum.TRUE.getType())
                .eq(EduStudentEnroll::getSchoolId, schoolId)
                .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName());
        Long lqCount = eduStudentEnrollService.count(lqQuery);
        if ((studentEnrollList.size() + lqCount) > enrolment) {
            throw new AppException("该报名类别录取人数大于计划招生人数，请核对");
        }
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        //todo 全市录取判断
        studentEnrollList.forEach(
                item -> {

                    item.setEnrollStatus(EnrollStatusFormalEnum.lq.getType());
                    item.setAdmitFlag(BoolEnum.TRUE.getType());
                    item.setAdmitTime(new Date());
                    item.setAdmitRemarks("报名人数未达计划数批量录取");
                    item.setAdmitUserId(SessionUtil.getSessionInfo().getUserId());


                });
        try {
            redisHelper.set(reidsKey, 1, 600);
            eduStudentEnrollService.updateBatchById(studentEnrollList);
        } catch (Exception e) {
            throw new AppException("保存数据异常" + e.getMessage());
        } finally {
            redisHelper.del(reidsKey);
        }
        studentEnrollList.forEach(item -> {
            eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getMotherIdcard());
        });
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0024", title = "义务教育民转公停止招生", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0024",
            operationName = "义务教育民转公停止招生",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywMzgStop(StudentEnrollStopVO vo) {

        this.ywStop(vo);
    }

    private void ywStop(StudentEnrollStopVO vo) {
        if (StringUtils.isBlank(vo.getSchoolId())) {
            vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        }
        String reidsKey = stopKey + vo.getSchoolId();
        if (redisHelper.hasKey(reidsKey)) {
            throw new AppException("系统正在执行中，请稍后！");
        }

        int year = 0;
        year = eduHelper.thisYear();
        QueryWrapper<EduEnrollmenBrochure> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, year)
                .eq(EduEnrollmenBrochure::getSchoolId, vo.getSchoolId());
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(queryWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }
        if (StringUtils.isBlank(vo.getAspirationType())) {
            vo.setAspirationType("0");
        }
        EduSchool eduSchool = eduSchoolService.getById(SessionUtil.getSessionInfo().getOrgId());

        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("招生已停止");
        }
        eduEnrollmenBrochure.setEndRegistration(BoolEnum.TRUE.getType());
        eduEnrollmenBrochureService.updateById(eduEnrollmenBrochure);
        //所有未录取的改成不录取
        List<String> dlqList = new ArrayList<>();
        dlqList.add(EnrollStatusFormalEnum.hy.getType());
        dlqList.add(EnrollStatusFormalEnum.fs.getType());
        dlqList.add(EnrollStatusFormalEnum.dlq.getType());
        dlqList.add(EnrollStatusFormalEnum.dsh.getType());
        QueryWrapper<EduStudentEnroll> studentEnrollQueryWrapper = new QueryWrapper<>();
        studentEnrollQueryWrapper.lambda().eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getAspirationType, vo.getAspirationType())
                .in(EduStudentEnroll::getEnrollStatus, dlqList);

        List<EduStudentEnroll> studentEnrollList =
                eduStudentEnrollService.list(studentEnrollQueryWrapper);
        if (!CollectionUtils.isEmpty(studentEnrollList)) {
            studentEnrollList.forEach(
                    item -> {
                        if (item.getAuthStatus().equals(AuthStatusEnum.NODO.getType())) {
                            item.setAuthStatus(AuthStatusEnum.NO.getType());
                            item.setAuthTime(new Date());
                            item.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
                            item.setAuthRemarks("停止招生，批量改为审核不通过");
                        }
                        item.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
                        item.setAdmitFlag(BoolEnum.FALSE.getType());
                        item.setAdmitTime(new Date());
                        item.setAdmitRemarks("停止招生，批量改为不录取");
                    });
            try {
                redisHelper.set(reidsKey, 1, 600);
                eduStudentEnrollService.updateBatchById(studentEnrollList);
            } catch (Exception e) {
                throw new AppException("保存数据异常" + e.getMessage());
            } finally {
                redisHelper.del(reidsKey);
            }
            studentEnrollList.forEach(item -> {
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getMotherIdcard());
            });
        }

    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0026", title = "义务教育民转公审核", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0026",
            operationName = "义务教育民转公审核",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywMzgAudit(StudentEnrollSaveVO vo) {
        this.auth(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0027", title = "义务教育民转公单个录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0027",
            operationName = "义务教育民转公单个录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollLqVO ywMzgApply(StudentEnrollSaveVO vo) {
        return this.admit(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0037", title = "义务教育教育局报名复审", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0037",
            operationName = "义务教育教育局报名复审",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywReview(StudentEnrollSaveVO vo) {
        this.review(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0034", title = "义务教育教育局单个录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0034",
            operationName = "义务教育教育局单个录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollLqVO ywAdmit(StudentEnrollSaveVO vo) {
        return this.admit(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0035", title = "义务教育公办学校批量录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0035",
            operationName = "义务教育公办学校批量录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollLqVO ywAdmitBatch(StudentEnrollSaveVO vo) {
        StudentEnrollLqVO ret = null;
        if (!CollectionUtils.isEmpty(vo.getStudentEnrollIdList())) {
            for (String studentEnrollId : vo.getStudentEnrollIdList()) {
                LambdaQueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<EduStudentEnroll>().lambda().eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                        .eq(EduStudentEnroll::getYear, eduHelper.thisYear());
                List<EduStudentEnroll> eduStudentEnrolls = eduStudentEnrollService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrolls)) {
                    if (!eduStudentEnrolls.get(0).getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType())) {
                        throw new AppException("存在未复审通过的数据");
                    }
                    StudentEnrollSaveVO admitVO = new StudentEnrollSaveVO();
                    admitVO.setAdmitFlag(vo.getAdmitFlag());
                    admitVO.setAdmitRemarks(vo.getAdmitRemarks());
                    admitVO.setStudentEnrollId(studentEnrollId);
                    this.admit(admitVO);
                }
            }
        }
        return ret;
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0029", title = "义务教育民办报名摇号信息导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void exportYwMbApplyInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {

        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    private void setData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentEnrollQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            if (vo.getYear() == null) {
                throw new AppException("招生年度不能为空");
            }
            QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
            brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, vo.getYear())
                    .eq(EduEnrollmenBrochure::getSchoolId, SessionUtil.getSessionInfo().getOrgId());
            EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
            if (eduEnrollmenBrochure == null) {
                throw new AppException("未找到学校招生方案信息");
            }
            EduSchool eduSchool = eduSchoolService.getById(SessionUtil.getSessionInfo().getOrgId());

            if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
                throw new AppException("招生已停止，不能导出");
            }

            PageInfo<EduStudentEnrollVO> pageInfo = getYwApplyList(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Map<String, Object>> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentEnrollVO studentEnrollVO : pageInfo.getList()) {
                    list.add(BeanUtil.beanToMap(studentEnrollVO, false, true));
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0030", title = "义务教育民办摇号信息导入", funcType = FuncTypeEnum.other)
    public YwMbApplyFileVO inputYwMbApplyInfo(YwMbApplyFileVO vo, MultipartFile file) {
        int year = eduHelper.thisYear();
        String schoolId = "";
        if (StringUtils.isEmpty(vo.getSchoolId())) {
            schoolId = SessionUtil.getSessionInfo().getOrgId();
        } else {
            schoolId = vo.getSchoolId();
        }
        QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
        brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, year)
                .eq(EduEnrollmenBrochure::getSchoolId, schoolId);
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到学校招生方案信息");
        }
        EduSchool eduSchool = eduSchoolService.getById(schoolId);

        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("招生已停止，不能导入");
        }

        List<EduStudentEnrollVO> studentEnrollVOList = new ArrayList<>();
        List<EduStudentEnrollVO> studentEnrollVOList2 = new ArrayList<>();
        ExcelVO excelVO = Convert.convert(ExcelVO.class, vo);
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);
        InputStream in = null;
        try {
            in = file.getInputStream();
            List<Map<String, Object>> list = excelCommonHelper.readExcel(excelModelVO, in, true);
            JSONArray jsonArray = new JSONArray();
            jsonArray.addAll(list);
            studentEnrollVOList2 = jsonArray.toJavaList(EduStudentEnrollVO.class);

            //捆绑摇号
            for (EduStudentEnrollVO eduStudentEnrollVO : studentEnrollVOList2) {
                if (eduStudentEnrollVO.getApplyId().contains(",")) {
                    String[] applyIdArray = eduStudentEnrollVO.getApplyId().split(",");
                    String[] fullNameArray = eduStudentEnrollVO.getFullName().split(",");
                    String[] idCardArray = eduStudentEnrollVO.getIdcard().split(",");
                    for (int i = 0; i < applyIdArray.length; i++) {
                        EduStudentEnrollVO enroll = new EduStudentEnrollVO();
                        enroll.setApplyId(applyIdArray[i]);
                        enroll.setFullName(fullNameArray[i]);
                        enroll.setIdcard(idCardArray[i]);
                        enroll.setSerialNum(eduStudentEnrollVO.getSerialNum());
                        studentEnrollVOList.add(enroll);
                    }
                } else {
                    studentEnrollVOList.add(eduStudentEnrollVO);
                }
            }

        } catch (IOException e) {
            throw new AppException("导入异常：" + e.getMessage());
        }
        if (CollectionUtils.isEmpty(studentEnrollVOList)) {
            throw new AppException("导入数据不能为空");
        }

        for (EduStudentEnrollVO item : studentEnrollVOList) {
            if (item.getSerialNum() == null) {
                throw new AppException("存在摇号序号为空的条目！");
            }
        }

        String redisKey = REDIS_YHDR + schoolId;
        if (redisHelper.hasKey(redisKey)) {
            throw new AppException("上一次导入正在处理中，不能导入");
        } else {
            redisHelper.set(redisKey, "1", 300);
        }
        //过滤报名编号为空数据
        studentEnrollVOList = studentEnrollVOList.stream()
                .filter(
                        filterItem -> StringUtils.isNotBlank(filterItem.getApplyId()))
                .collect(Collectors.toList());

        List<EduStudentEnrollVO> errorList = new ArrayList<>();
        QueryWrapper<EduStudentEnroll> existsQueryWrapper = new QueryWrapper<>();
        existsQueryWrapper
                .lambda()
                .eq(EduStudentEnroll::getSchoolId, schoolId)
                .in(
                        EduStudentEnroll::getApplyId,
                        studentEnrollVOList.stream()
                                .map(EduStudentEnrollVO::getApplyId)
                                .collect(Collectors.toList()));
        List<EduStudentEnroll> studentEnrollList =
                eduStudentEnrollService.list(existsQueryWrapper);
        if (CollectionUtils.isEmpty(studentEnrollList)) {
            redisHelper.del(redisKey);
            throw new AppException("导入的报名编号在系统中未匹配到数据");
        }

        List<String> applyIdList =
                studentEnrollList.stream()
                        .map(EduStudentEnroll::getApplyId)
                        .collect(Collectors.toList());
        List<String> idcardList = new ArrayList<>();
        List<EduStudentEnroll> successList = new ArrayList<>();
        studentEnrollVOList.forEach(
                item -> {
                    if (item.getApplyId() == null || item.getSerialNum() == null) {
                        redisHelper.del(redisKey);
                        throw new AppException("模板有误!");
                    }
                    String remarks = "";
                    boolean flag = false;
                    if (StringUtils.isNotBlank(item.getIdcard())) {
                        if (idcardList.contains(item.getIdcard())) {
                            remarks += "存在重复学生身份证！";
                            flag = true;
                        } else {
                            idcardList.add(item.getIdcard());
                        }
                    }
                    if (!applyIdList.contains(item.getApplyId())) {
                        remarks += "根据报名编号查询不到学生信息！";
                        flag = true;
                    } else {
                        EduStudentEnroll eduStudentEnroll =
                                studentEnrollList.stream()
                                        .filter(
                                                filterItem ->
                                                        Objects.equals(
                                                                filterItem.getApplyId(),
                                                                item.getApplyId()))
                                        .collect(Collectors.toList())
                                        .get(0);
                        if (eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.lq.getType())) {
                            redisHelper.del(redisKey);
                            throw new AppException("录取工作已开始后不能导入摇号结果");
                        }
                        if (!eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.dlq.getType())) {
                            redisHelper.del(redisKey);
                            throw new AppException("数据异常：人员数据不是待录取状态，请联系管理员查找原因");
                        }
                        if (StringUtils.isNotBlank(item.getFullName())
                                && !StringUtils.equals(
                                item.getFullName(), eduStudentEnroll.getFullName())) {
                            remarks += "学生姓名预系统中的不匹配！";
                            flag = true;
                        }
                        if (StringUtils.isNotBlank(item.getIdcard())
                                && !StringUtils.equals(
                                item.getIdcard(), eduStudentEnroll.getIdcard())) {
                            remarks += "学生证件号码与系统中的不匹配！";
                            flag = true;
                        }

                        item.setStudentEnrollId(eduStudentEnroll.getStudentEnrollId());
                        if (!flag) {
                            eduStudentEnroll.setSerialNum(item.getSerialNum());
                            successList.add(eduStudentEnroll);
                            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
                            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
                            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());

                        }
                    }
                    if (flag) {
                        item.setRemarks(remarks);
                        errorList.add(item);
                    }
                });
        vo.setErrorList(errorList);
        vo.setErrorId(IdUtil.simpleUUID());

        if (!CollectionUtils.isEmpty(successList)) {
            eduStudentEnrollService.updateBatchById(successList);
            vo.setSuccessList(Convert.toList(EduStudentEnrollVO.class, successList));

        }
        redisHelper.del(redisKey);
        return vo;
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0031", title = "义务教育民办停止招生", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0031",
            operationName = "义务教育民办愿停止招生",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywMbStop(StudentEnrollStopVO vo) {

        this.ywStop(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0032", title = "义务教育民办审核", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0032",
            operationName = "义务教育民办第一志愿审核",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywMbAudit(StudentEnrollSaveVO vo) {
        this.auth(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0033", title = "义务教育民办单个录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0033",
            operationName = "义务教育民办第一志愿单个录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollLqVO ywMbApply(StudentEnrollSaveVO vo) {
        return this.admit(vo);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0042", title = "获取义务教育公办报名列表查询信息", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getYwGbApplyInfo(EduStudentEnrollQueryVO vo) {
        vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        vo.setOpType("0");
        PageInfo<EduStudentEnrollVO> pageInfo = this.getYwApplyList(vo);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0043", title = "义务教育公办报名审核", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0043",
            operationName = "义务教育公办报名审核",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywGbAudit(StudentEnrollSaveVO vo) {
        this.auth(vo);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0044", title = "义务教育公办报名录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0044",
            operationName = "义务教育公办报名录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollLqVO ywGbApply(StudentEnrollSaveVO vo) {
        return this.admit(vo);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0045", title = "义务教育公办报名信息导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void exportYwGbApplyInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        vo.setSchoolId(SessionUtil.getOrgId());
        vo.setOpType("0");
        if (vo.getYear() == null) {
            throw new AppException("招生年度不能为空");
        }
        this.exportYwApplyInfo(vo, response);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0046", title = "义务教育公办结束招生", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0046",
            operationName = "义务教育公办结束招生",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywGbStop(StudentEnrollStopVO vo) {
        if (StringUtils.isBlank(vo.getSchoolId())) {
            vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        }
        String reidsKey = stopKey + vo.getSchoolId();
        if (redisHelper.hasKey(reidsKey)) {
            throw new AppException("系统正在执行中，请稍后！");
        }

        int year = eduHelper.thisYear();
        EnrollCheckShLqVO checkShLqVO = new EnrollCheckShLqVO();
        checkShLqVO.setSchoolId(vo.getSchoolId());
        checkShLqVO.setYear(year);
        checkShLqVO.setOpType("0");
        this.checklq(checkShLqVO);
        QueryWrapper<EduEnrollmenBrochure> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, year)
                .eq(EduEnrollmenBrochure::getSchoolId, vo.getSchoolId());
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(queryWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }
        if (StringUtils.isBlank(vo.getAspirationType())) {
            vo.setAspirationType("0");
        }
        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("已停止招生");
        }
        eduEnrollmenBrochure.setEndRegistration(BoolEnum.TRUE.getType());

        eduEnrollmenBrochureService.updateById(eduEnrollmenBrochure);
        //所有未录取的改成不录取
        List<String> dlqList = new ArrayList<>();
        dlqList.add(EnrollStatusFormalEnum.hy.getType());
        dlqList.add(EnrollStatusFormalEnum.fs.getType());
        dlqList.add(EnrollStatusFormalEnum.dlq.getType());
        dlqList.add(EnrollStatusFormalEnum.dsh.getType());
        QueryWrapper<EduStudentEnroll> studentEnrollQueryWrapper = new QueryWrapper<>();
        studentEnrollQueryWrapper.lambda().eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getAspirationType, vo.getAspirationType())
                .in(EduStudentEnroll::getEnrollStatus, dlqList);
        List<EduStudentEnroll> studentEnrollList =
                eduStudentEnrollService.list(studentEnrollQueryWrapper);
        if (!CollectionUtils.isEmpty(studentEnrollList)) {
            studentEnrollList.forEach(
                    item -> {
                        if (item.getAuthStatus().equals(AuthStatusEnum.NODO.getType())) {
                            item.setAuthStatus(AuthStatusEnum.NO.getType());
                            item.setAuthTime(new Date());
                            item.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
                            item.setAuthRemarks("停止招生，批量改为审核不通过");
                        }
                        item.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
                        item.setAdmitFlag(BoolEnum.FALSE.getType());
                        item.setAdmitTime(new Date());
                        item.setAdmitRemarks("停止招生，批量改为不录取");
                    });
            try {
                redisHelper.set(reidsKey, 1, 600);
                eduStudentEnrollService.updateBatchById(studentEnrollList);
            } catch (Exception e) {
                throw new AppException("保存数据异常" + e.getMessage());
            } finally {
                redisHelper.del(reidsKey);
            }
            studentEnrollList.forEach(item -> {
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(item.getMotherIdcard());
            });
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0047", title = "根据学校id配置表查询", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public List<SchoolConfigVO> querySchoolConfigBySchoolId(SchoolConfigQueryVO vo) {
        if (StringUtils.isBlank(vo.getOrgId())) {
            throw new AppException("学校id不能为空");
        }
        int year;
        String orgId = vo.getOrgId();
        QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
        brochureQueryWrapper
                .lambda()
                .eq(EduEnrollmenBrochure::getSchoolId, orgId)
                .orderByDesc(EduEnrollmenBrochure::getYear)
                .last("limit 1");
        if (vo.getYear() != null) {
            brochureQueryWrapper
                    .lambda()
                    .eq(EduEnrollmenBrochure::getYear, vo.getYear());
        }
        EduEnrollmenBrochure brochure =
                eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
        if (ObjectUtils.isEmpty(brochure)) {
            throw new AppException("查询不到招生方案信息");
        } else {
            year = brochure.getYear();
        }
        String eFlag = "0";
        QueryWrapper<EduAppointSchool> eduAppointSchoolQueryWrapper = new QueryWrapper<>();
        eduAppointSchoolQueryWrapper.lambda().eq(EduAppointSchool::getNewSchoolId, orgId)
                .eq(EduAppointSchool::getStatus, BoolEnum.TRUE.getType())
                .eq(EduAppointSchool::getYear, year);
        if (eduAppointSchoolService.count(eduAppointSchoolQueryWrapper) > 0) {
            eFlag = "1";
        }
        SchoolConfigQueryVO schoolConfigQueryVO = new SchoolConfigQueryVO();
        schoolConfigQueryVO.setOrgId(vo.getOrgId());
        schoolConfigQueryVO.setAccessToken(vo.getAccessToken());
        schoolConfigQueryVO.setOpRouterId(vo.getOpRouterId());
        schoolConfigQueryVO.setYear(year);
        schoolConfigQueryVO.setStatus(BoolEnum.TRUE.getType());
        schoolConfigQueryVO.setAuthStatus(AuthStatusEnum.YES.getType());
        schoolConfigQueryVO.setZsFlag(vo.getZsFlag());
        if (StringUtils.isBlank(vo.getSpecialFlag())) {
            schoolConfigQueryVO.setSpecialFlag(BoolEnum.FALSE.getType());
        } else {
            schoolConfigQueryVO.setSpecialFlag(vo.getSpecialFlag());
        }
        PageInfo<SchoolConfigVO> pageInfo = eduSchoolConfigIntegration.getYwSchoolConfigInfo(schoolConfigQueryVO);
        List<SchoolConfigVO> list = pageInfo.getList();
        if (CollectionUtils.isEmpty(list)) {
            return list;
        }

        for (SchoolConfigVO schoolConfigVO : list) {
            schoolConfigVO.setEFlag(eFlag);
        }
        //List<String> configTypeNameList=list.stream().map(SchoolConfigVO::getConfigTypeName).distinct().collect(Collectors.toList());
        //公办认为只有一个招生计划的类别，所以查询时候不做控制，民办目前不配表单

        if (BoolEnum.FALSE.getType().equals(schoolConfigQueryVO.getSpecialFlag())) {
            QueryWrapper<EduFormEnroll> formQueryWrapper = new QueryWrapper<>();
            formQueryWrapper
                    .lambda()
                    .eq(EduFormEnroll::getSchoolId, orgId)
                    //.in(EduFormEnroll::getConfigTypeName, configTypeNameList)
                    .eq(EduFormEnroll::getStatus, "on")
                    .eq(EduFormEnroll::getYear, year)
                    .orderByAsc(EduFormEnroll::getOrderNo);
            List<EduFormEnroll> form = eduFormEnrollService.list(formQueryWrapper);
            if (CollectionUtils.isEmpty(form)) {
                return list;
            }
            List<FormAppQueryVO> formAppQueryVO = Convert.toList(FormAppQueryVO.class, form);
            dictHelper.valueToName(formAppQueryVO, Arrays.asList(EduFormEnrollDictEnum.values()));
            for (SchoolConfigVO schoolConfigVO : list) {
                if (StringUtils.isNotBlank(schoolConfigVO.getConfigTypeName())) {
                    schoolConfigVO.setFormList(formAppQueryVO);
                }
            }
        } else {
            if (StringUtils.isBlank(brochure.getSpecialIds())) {
                return list;
            }
            List<String> specialIdList = Arrays.stream(brochure.getSpecialIds().split(",")).map(s -> s).collect(Collectors.toList());
            QueryWrapper<EduFormSpecial> formQueryWrapper = new QueryWrapper<>();
            formQueryWrapper
                    .lambda()
                    .in(EduFormSpecial::getFormSpecialId, specialIdList)
                    //.in(EduForm::getConfigTypeName, configTypeNameList)
                    .eq(EduFormSpecial::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduFormSpecial::getYear, year)
                    .orderByAsc(EduFormSpecial::getOrderNo);
            List<EduFormSpecial> form = eduFormSpecialService.list(formQueryWrapper);
            if (CollectionUtils.isEmpty(form)) {
                return list;
            }
            List<FormAppQueryVO> formAppQueryVO = new ArrayList<>();
            for (EduFormSpecial eduFormSpecial : form) {
                FormAppQueryVO formVO = new FormAppQueryVO();
                formVO.setFormId(eduFormSpecial.getFormSpecialId());
                formVO.setConfigType(eduFormSpecial.getSmallClassKey() + "");
                formVO.setFormType(eduFormSpecial.getBigClassKey() + "");
                formVO.setFormClass(eduFormSpecial.getSmallClassKey() + "");
                formVO.setConfigName(eduFormSpecial.getSmallClassValue());
                formVO.setConfigTypeName(eduFormSpecial.getBigClassValue());
                formAppQueryVO.add(formVO);
            }
            for (SchoolConfigVO schoolConfigVO : list) {
                if (StringUtils.isNotBlank(schoolConfigVO.getConfigTypeName())) {
                    schoolConfigVO.setFormList(formAppQueryVO);
                }
            }
        }

        return list;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0048", title = "义务教育学校录入报名人员", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0048",
            operationName = "义务教育学校录入报名人员",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void schoolAddEnroll(SaveStudentEnrollVO vo) {

        EduStudentEnroll enroll = null;
        //义务端学校录入报名人员保存校验
        saveCheckStudentEnroll(vo);

        String schoolId = vo.getSchoolId();
        if (StringUtils.isBlank(schoolId)) {
            schoolId = SessionUtil.getSessionInfo().getOrgId();
        }
        EduSchool eduSchool = eduSchoolService.getById(schoolId);
        if (eduSchool == null) {
            throw new AppException("未找到学校信息");
        }
        vo.setSchoolName(eduSchool.getSchoolName());
        vo.setSchoolNature(eduSchool.getSchoolNature());
        vo.setStreet(eduSchool.getStreet());
        vo.setSchoolCategory(eduSchool.getSchoolCategory());
        vo.setAreaCode(eduSchool.getAreaCode());
        if (vo.getYear() == null) {
            int year;
            year = eduHelper.thisYear();
            vo.setYear(year);
        }

        //时间控制
        //判断是否在年度招生时间中
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setYear(vo.getYear());
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        if (eduOperationCacheVO == null) {
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO xxOperation = operation.get("YW023");//学校录入时间
        if (xxOperation == null) {
            throw new AppException(vo.getYear() + "年度义务段学校线下报名录入工作尚未开始");
        }
        if (!xxOperation.isFlag()) {
            if ("1".equalsIgnoreCase(xxOperation.getType()) || "3".equalsIgnoreCase(xxOperation.getType())) {
                throw new AppException(vo.getYear() + "年度义务段学校线下报名录入工作尚未开始");
            } else {
                throw new AppException(vo.getYear() + "年度义务段学校线下报名录入工作已结束");
            }
        }
        //检验是否在黑名单中，黑名单中不能线下录入
        QueryWrapper<EduStudentEnrollBlacklist> blacklistQueryWrapper = new QueryWrapper<>();
        blacklistQueryWrapper.lambda().eq(EduStudentEnrollBlacklist::getIdcard, vo.getIdcard())
                .eq(EduStudentEnrollBlacklist::getYear, vo.getYear())
                .eq(EduStudentEnrollBlacklist::getStatus, BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollBlacklist::getAreaCode, eduSchool.getAreaCode());
        if (eduStudentEnrollBlacklistService.count(blacklistQueryWrapper) > 0) {
            throw new AppException("该学生申请过退出报名，不能重新录入");
        }

        //加锁进行判断
        RLock lock = redissonClient.getLock(EduCache.EDU_YW_STUDENT_ENROLL_LOCK + vo.getIdcard());
        boolean isGetLock = false;
        try {
            isGetLock = lock.tryLock(5, 60, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.error("异常：" + e.getMessage());
            throw new RuntimeException(e.getMessage());
        }
        if (isGetLock) {
            try {
                //判断学校录入指标管理是否有配置存在
                QueryWrapper<EduSchoolLr> lrQueryWrapper = new QueryWrapper<>();
                lrQueryWrapper.lambda()
                        .eq(EduSchoolLr::getYear, vo.getYear())
                        .eq(EduSchoolLr::getSchoolId, vo.getSchoolId());
                EduSchoolLr schoolLr = eduSchoolLrService.getOne(lrQueryWrapper, false);
                if (schoolLr != null) {
                    if (schoolLr.getLrCount() == 0) {
                        throw new AppException(schoolLr.getSchoolName() + "的可录入人数为0，请联系教育局进行配置！");
                    }
                    List<String> statusList = new ArrayList<>();
                    statusList.add(EnrollStatusFormalEnum.dsh.getType());
                    statusList.add(EnrollStatusFormalEnum.hy.getType());
                    statusList.add(EnrollStatusFormalEnum.lq.getType());
                    statusList.add(EnrollStatusFormalEnum.fs.getType());
                    statusList.add(EnrollStatusFormalEnum.dlq.getType());
                    long enrollStudentCount = eduStudentEnrollService.count(Wrappers.<EduStudentEnroll>lambdaQuery()
                            .eq(EduStudentEnroll::getYear, vo.getYear())
                            .in(EduStudentEnroll::getEnrollStatus, statusList)
                            .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                            .eq(EduStudentEnroll::getSource, "6"));
                    if (enrollStudentCount >= schoolLr.getLrCount()) {
                        throw new AppException("学校线下录入的人数大于系统配置人数指标，无法进行学生录入，请联系教育局进行配置");
                    }

                }


                List<String> enrollStatusList = new ArrayList<>();
                enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
                QueryWrapper<EduStudentEnroll> otherQueryWrapper = new QueryWrapper<>();
                otherQueryWrapper.lambda().ne(EduStudentEnroll::getSchoolId, schoolId)
                        .eq(EduStudentEnroll::getYear, vo.getYear())
                        .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                        .eq(EduStudentEnroll::getIdcard, vo.getIdcard());
                if (eduStudentEnrollService.count(otherQueryWrapper) > 0) {
                    throw new AppException("该学生已在市内其他学校待审核/待录取/录取，不能直接录入，如有疑问，请联系基教科核对");
                }
                if (StringUtils.isNotBlank(vo.getStudentEnrollId())) {
                    enroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
                    if ("2".equals(enroll.getEnrollStatus())) {
                        throw new AppException("该学生已是录取状态，请核对");
                    }
                    if (!enroll.getFormId().equalsIgnoreCase(vo.getFormId())) {
                        enroll.setApplyId(null);
                    }

                } else {
                    QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                    enrollQueryWrapper.lambda().eq(EduStudentEnroll::getSchoolId, schoolId)
                            .eq(EduStudentEnroll::getYear, vo.getYear())
                            .eq(EduStudentEnroll::getIdcard, vo.getIdcard());
                    List<EduStudentEnroll> eduStudentEnrollList = eduStudentEnrollService.list(enrollQueryWrapper);
                    if (!CollectionUtils.isEmpty(eduStudentEnrollList)) {
                        enroll = eduStudentEnrollList.get(0);
                        if ("2".equals(enroll.getEnrollStatus())) {
                            throw new AppException("该学生已是录取状态，请核对");
                        }
                        if ("3".equals(enroll.getEnrollStatus())) {
                            throw new AppException("该学生业务操作为不予录取，如需重新录入，请联系基教科处理数据");
                        }
                    } else {

                        enroll = Convert.convert(EduStudentEnroll.class, vo);
                        if ("0".equals(vo.getSchoolNature())) {
                            if (StringUtils.isBlank(vo.getConfigTypeName())) {
                                vo.setConfigTypeName("公办");
                            }
                        }
                        enroll.setStudentEnrollId(IdUtil.simpleUUID());
                        enroll.setSchoolId(schoolId);
                    }
                }
                //进行学生录入
                QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
                brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, vo.getYear())
                        .eq(EduEnrollmenBrochure::getSchoolId, vo.getSchoolId());
                EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
                if (eduEnrollmenBrochure == null) {
                    throw new AppException("未找到招生方案信息");
                }
                //超过计划数不能录取
                QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
                configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                        .eq(EduSchoolConfig::getSchoolId, vo.getSchoolId())
                        .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduSchoolConfig::getYear, vo.getYear());
                if ("1".equals(vo.getSchoolNature()) || "2".equals(vo.getSchoolNature())) {

                    //民办
                    configQueryWrapper.lambda().eq(EduSchoolConfig::getConfigTypeName, vo.getConfigTypeName());
                }
                EduSchoolConfig eduSchoolConfig = eduSchoolConfigService.getOne(configQueryWrapper, false);
                StudentEnrollLqVO retVO = new StudentEnrollLqVO();
                //计划人数
                Integer enrolment = 0;
                if (eduSchoolConfig != null) {
                    enrolment = eduSchoolConfig.getEnrolment() == null ? 1000 : eduSchoolConfig.getEnrolment();
                } else {
                    enrolment = 1000;
                }
                //已录取人数
                QueryWrapper<EduStudentEnroll> lqQuery = new QueryWrapper<>();
                lqQuery.lambda().eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                        .eq(EduStudentEnroll::getYear, vo.getYear())
                        .eq(EduStudentEnroll::getAdmitFlag, BoolEnum.TRUE.getType())
                        .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId());
                if ("1".equals(vo.getSchoolNature()) || "2".equals(vo.getSchoolNature())) {
                    //民办
                    lqQuery.lambda().eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName());
                }
                Long lqCount = eduStudentEnrollService.count(lqQuery);
                if (lqCount >= enrolment) {
                    throw new AppException("录取人数已到达计划人数，如还需录取，请联系基教科修改招生计划");
                }
                enroll.setConfigName(vo.getConfigName());
                enroll.setConfigTypeName(vo.getConfigTypeName());
                enroll.setFormId(vo.getFormId());
                enroll.setRemarks(vo.getRemarks());
                enroll.setSource("6");//学校录入
                enroll.setAdmitFlag(BoolEnum.TRUE.getType());
                enroll.setAuthStatus(AuthStatusEnum.YES.getType());
                enroll.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
                enroll.setAuthTime(new Date());
                enroll.setEnrollStatus("2");
                enroll.setParam20(vo.getParam20());
                enroll.setAdmitTime(new Date());
                enroll.setAspirationType("0");
                enroll.setAdmitRemarks("学校直接录入录取");
                enroll.setDeployFlag(BoolEnum.FALSE.getType());
                QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().eq(EduStudentEnroll::getYear, enroll.getYear())
                        .eq(EduStudentEnroll::getIdcard, enroll.getIdcard())
                        .eq(EduStudentEnroll::getEnrollStatus, "2")
                        .ne(EduStudentEnroll::getSchoolId, schoolId);
                if (eduStudentEnrollService.count(enrollQueryWrapper) > 0) {
                    throw new AppException("已被金华市区其他学校录取");
                }
                //调用金华接口判断是否已录取
                EduSyncJhDeleteQueryVO syncJhDeleteQueryVO = new EduSyncJhDeleteQueryVO();
                syncJhDeleteQueryVO.setIdcard(enroll.getIdcard());
                syncJhDeleteQueryVO.setName(enroll.getFullName());
                syncJhDeleteQueryVO.setApplyCountyCode(enroll.getAreaCode());
                EduSyncExistInfo eduSyncExistInfo = syncJhDeleteIntegration.querySyncInfo(syncJhDeleteQueryVO);
                if (!ObjectUtils.isEmpty(eduSyncExistInfo)
                        && StringUtils.isNotBlank(eduSyncExistInfo.getType())
                        && eduSyncExistInfo.getType().equals("3")) {
                    throw new AppException(eduSyncExistInfo.getName() + "在" + eduSyncExistInfo.getApplyEduName() + "已录取！");
                }
                this.setPersonId(enroll);
                if (StringUtils.isBlank(enroll.getApplyId())) {
                    Integer orderNo = 0;
                    if ("0".equals(enroll.getSchoolNature())) {
                        if (StringUtils.isBlank(enroll.getFormId())) {
                            throw new AppException("报名表单id不能为空");
                        }
                        EduFormEnroll eduFormEnroll = eduFormEnrollService.getById(enroll.getFormId());
                        enroll.setSpecialFlag(BoolEnum.FALSE.getType());
                        if (eduFormEnroll == null) {
                            EduFormSpecial eduFormSpecial = eduFormSpecialService.getById(enroll.getFormId());
                            if (eduFormSpecial == null) {
                                throw new AppException("未匹配到学校配置的报名表单，如果疑问，请拨打学校电话了解详细情况");
                            }
                            orderNo = 99;
                            enroll.setConfigTypeName(eduFormSpecial.getBigClassValue());
                            enroll.setSpecialFlag(BoolEnum.TRUE.getType());

                        } else {
                            if (!eduFormEnroll.getValidStatus().equals(BoolEnum.TRUE.getType())) {
                                throw new AppException("学校配置报名表单已无效，如果疑问，请拨打学校电话了解详细情况");
                            }
                            orderNo = eduFormEnroll.getOrderNo();
                            //判断年龄是否符合，不是特殊通道类别，需要判断年龄
                            if (StringUtils.isBlank(vo.getBirthYmd())) {
                                throw new AppException("出生日期不能为空");
                            }
                            String birthday = "";
                            if (vo.getBirthYmd().length() >= 8) {
                                birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
                            } else if (vo.getBirthYmd().length() == 6) {
                                birthday = vo.getBirthYmd() + "01";
                            } else {
                                throw new AppException("出生日期格式不正确");
                            }
                            Integer birthYmd = Integer.parseInt(birthday);
                            if (eduSchoolConfig.getStartAge() != null) {
                                Integer startBirthday =
                                        Integer.parseInt(
                                                DatePattern.PURE_DATE_FORMAT.format(eduSchoolConfig.getStartAge()));
                                if (birthYmd < startBirthday) {
                                    throw new AppException("年龄不符");
                                }
                            }
                            if (eduSchoolConfig.getEndAge() != null) {
                                Integer endBirthday =
                                        Integer.parseInt(
                                                DatePattern.PURE_DATE_FORMAT.format(eduSchoolConfig.getEndAge()));
                                if (birthYmd > endBirthday) {
                                    throw new AppException("年龄不符");
                                }
                            }
                        }

                    } else {

                        if (StringUtils.isBlank(enroll.getConfigTypeName())) {
                            throw new AppException(eduSchool.getSchoolName() + "的报名类别不能为空");
                        }
                        QueryWrapper<EduSchoolConfig> schoolConfigMbQueryWrapper = new QueryWrapper<>();
                        schoolConfigMbQueryWrapper
                                .lambda()
                                .eq(EduSchoolConfig::getSchoolId, enroll.getSchoolId())
                                .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                                .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                                .eq(EduSchoolConfig::getConfigTypeName, enroll.getConfigTypeName())
                                .eq(EduSchoolConfig::getYear, enroll.getYear());
                        EduSchoolConfig schoolConfigMb = eduSchoolConfigService.getOne(schoolConfigMbQueryWrapper, false);
                        if (schoolConfigMb == null) {
                            throw new AppException(enroll.getYear() + "年度报名学校报名类别不匹配，如有疑问，请拨打学校电话了解详细情况");
                        }
                        if (schoolConfigMb.getOrderNo() == null) {
                            throw new AppException(enroll.getYear() + "年度报名学校招生计划设置有误，如有疑问，请拨打学校电话了解详细情况");
                        }
                        orderNo = schoolConfigMb.getOrderNo();
                    }
                    String applyId = this.getApplyId(enroll.getYear(), enroll.getSchoolNature(), eduSchool.getSchoolNum(), orderNo, enroll.getSchoolId(), 1);
                    enroll.setApplyId(applyId);
                }
                //判断是否随迁
                if (StringUtils.isBlank(enroll.getFollowingFlag())) {
                    QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
                    queryWrapper.lambda().eq(EduHousehold::getYear, enroll.getYear())
                            .eq(EduHousehold::getIdcard, enroll.getIdcard())
                            .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                            .eq(EduHousehold::getAreaCode, enroll.getAreaCode());
                    if (eduHouseholdService.count(queryWrapper) > 0) {
                        //有户籍认为非随迁
                        enroll.setFollowingFlag(BoolEnum.TRUE.getType());
                    } else {
                        if (BoolEnum.TRUE.getType().equalsIgnoreCase(enroll.getSpecialFlag())) {
                            //特殊通道认为非随迁
                            enroll.setFollowingFlag(BoolEnum.TRUE.getType());
                        } else {
                            if ("A".equalsIgnoreCase(enroll.getConfigName()) || "B".equalsIgnoreCase(enroll.getConfigName())) {
                                //A类B类认为是非随迁
                                enroll.setFollowingFlag(BoolEnum.TRUE.getType());
                            } else {
                                enroll.setFollowingFlag(BoolEnum.FALSE.getType());
                            }
                        }
                    }
                }
                try {
                    eduStudentEnrollService.saveOrUpdate(enroll);
                } catch (Exception e) {
                    throw new AppException("报名编号重复，请重新点击保存");
                }
                insertEduStudentEnrollPre(vo);
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            } finally {
                lock.unlock();
                redisHelper.del(EduCache.EDU_YW_STUDENT_ENROLL_LOCK + vo.getIdcard());
            }
        }

    }

    /**
     * 判断预采集中是否有数据，如果没有就进行增加
     *
     * @param vo
     */
    private void insertEduStudentEnrollPre(SaveStudentEnrollVO vo) {
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EduStudentEnrollPre::getYear, eduHelper.thisYear())
                .eq(EduStudentEnrollPre::getIdcard, vo.getIdcard());
        if (eduStudentEnrollPreService.count(queryWrapper) == 0) {
            //没有预采集数据，需要新增预采集数据
            EduStudentEnrollPre eduStudentEnrollPre = new EduStudentEnrollPre();
            BeanUtil.copyProperties(vo, eduStudentEnrollPre);
            eduStudentEnrollPre.setEnrollPreType(EnrollPreTypeEnum.lr.getType());
            eduStudentEnrollPre.setAuthStatus(AuthStatusEnum.YES.getType());
            eduStudentEnrollPreService.save(eduStudentEnrollPre);
        }

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0050", title = "管理员查询摇号数据", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getEnrollLottery(EduStudentEnrollQueryVO vo) {

        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        //摇号数据只取审核通过待录取数据
        enrollQueryWrapper.lambda()
                .eq(EduStudentEnroll::getYear, vo.getYear())
                .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .in(!CollectionUtils.isEmpty(vo.getEnrollStatusList()), EduStudentEnroll::getEnrollStatus, vo.getEnrollStatusList())
                .in(!CollectionUtils.isEmpty(vo.getAspirationTypeList()), EduStudentEnroll::getAspirationType, vo.getAspirationTypeList())
                .eq(StringUtils.isNotBlank(vo.getFatherIdcard()), EduStudentEnroll::getFatherIdcard, vo.getFatherIdcard())
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType())
                .eq(StringUtils.isNotBlank(vo.getFollowingFlag()), EduStudentEnroll::getFollowingFlag, vo.getFollowingFlag())
                .eq(StringUtils.isNotBlank(vo.getEnrollStatus()),EduStudentEnroll::getEnrollStatus, vo.getEnrollStatus())
                .orderByAsc(EduStudentEnroll::getSerialNum);
        List<EduStudentEnroll> list = eduStudentEnrollService.list(enrollQueryWrapper);

        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentEnroll> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollVO> resultList = Convert.toList(EduStudentEnrollVO.class, pageInfo.getList());
        // 转义数据字典值
        dictHelper.valueToName(resultList, Arrays.asList(EduYwEnrollDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }


    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0051", title = "管理员查询摇号数据导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void exportEnrollLottery(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setDataEnrollLottery(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }

    }

    private void setDataEnrollLottery(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentEnrollQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            vo.setDesensitizeFlag(false);
            PageInfo<EduStudentEnrollVO> pageInfo = this.getEnrollLotteryList(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Object> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentEnrollVO eduStudentEnrollVO : pageInfo.getList()) {
                    list.add(eduStudentEnrollVO);
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeBean(excelWriter, list);
            } else {
                excelCommonHelper.writeBean(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setDataEnrollLottery(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0060", title = "摇号导出人员缓存清除", funcType = FuncTypeEnum.query)
    public void clearEnrollLotteryCache(EduStudentEnrollQueryVO vo) {
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isBlank(vo.getSchoolId())) {
            vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        }
        //摇号数据只取审核通过待录取数据
        enrollQueryWrapper.lambda()
                .eq(EduStudentEnroll::getYear, vo.getYear())
                .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                .eq(StringUtils.isNotBlank(vo.getFatherIdcard()), EduStudentEnroll::getFatherIdcard, vo.getFatherIdcard())
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentEnroll::getAspirationType, vo.getAspirationType())
                .eq(StringUtils.isNotBlank(vo.getFollowingFlag()), EduStudentEnroll::getFollowingFlag, vo.getFollowingFlag())
                .eq(EduStudentEnroll::getEnrollStatus, "1")
                .orderByAsc(EduStudentEnroll::getSerialNum);
        List<EduStudentEnroll> list = eduStudentEnrollService.list(enrollQueryWrapper);

        for (EduStudentEnroll enroll : list) {
            eduEnrollClearCacheHelper.clearCacheMyEnroll(enroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(enroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(enroll.getMotherIdcard());

        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0061", title = "义务段正式报名管理缓存清除", funcType = FuncTypeEnum.query)
    public void clearYwEnrollCache(EduStudentEnrollQueryVO vo) {
        int pageNum = 1;
        vo.setPageNum(pageNum);
        if (StringUtils.isBlank(vo.getSchoolId())) {
            vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        }
        vo.setPageSize(500);

        PageInfo<EduStudentEnrollVO> pageInfo = this.getList(vo);
        if (!CollectionUtils.isEmpty(pageInfo.getList())) {
            for (EduStudentEnrollVO enrollVO : pageInfo.getList()) {
                eduEnrollClearCacheHelper.clearCacheMyEnroll(enrollVO.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(enrollVO.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnroll(enrollVO.getMotherIdcard());
            }
        }

        if (pageInfo.isHasNextPage()) {
            vo.setPageNum(pageNum + 1);
            ;
            clearYwEnrollCache(vo);
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0062", title = "学生线下录入学生修改", funcType = FuncTypeEnum.query)
    @Transactional
    public EduStudentEnrollVO editStudentEnrollBySchool(SaveStudentEnrollVO vo) {
        String studentEnrollId = vo.getStudentEnrollId();
        if (ObjectUtils.isEmpty(studentEnrollId)) {
            throw new AppException("报名主键不能为空！");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(studentEnrollId);
        if (ObjectUtils.isEmpty(eduStudentEnroll)) {
            throw new AppException("数据不存在，请刷新后重试！");
        }
        //修改前参数校验
        saveCheckStudentEnroll(vo);
        Integer year = eduHelper.thisYear();
        //时间控制
        //判断是否在年度招生时间中
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        if (eduOperationCacheVO == null) {
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO xxOperation = operation.get("YW023");//学校录入时间
        if (xxOperation == null) {
            throw new AppException(year + "年度义务段学校线下报名录入工作尚未开始");
        }
        if (!xxOperation.isFlag()) {
            if ("1".equalsIgnoreCase(xxOperation.getType()) || "3".equalsIgnoreCase(xxOperation.getType())) {
                throw new AppException(year + "年度义务段学校线下报名录入工作尚未开始");
            } else {
                throw new AppException(year + "年度义务段学校线下报名录入工作已结束");
            }
        }

        //1.修改当前学校的报名信息
        eduStudentEnrollService.update(Wrappers.<EduStudentEnroll>lambdaUpdate()
                .eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                .set(EduStudentEnroll::getIdcard, vo.getIdcard())
                .set(EduStudentEnroll::getCardType, vo.getCardType())
                .set(EduStudentEnroll::getFullName, vo.getFullName())
                .set(EduStudentEnroll::getSex, vo.getSex())
                .set(EduStudentEnroll::getHouseholdPlace, vo.getHouseholdPlace())
                .set(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                .set(StringUtils.isNotBlank(vo.getConfigName()), EduStudentEnroll::getConfigName, vo.getConfigName())
                .set(StringUtils.isNotBlank(vo.getConfigNameAlias()), EduStudentEnroll::getConfigNameAlias, vo.getConfigNameAlias())
                .set(StringUtils.isNotBlank(vo.getServiceFlag()), EduStudentEnroll::getServiceFlag, vo.getServiceFlag())
                .set(StringUtils.isNotBlank(vo.getAborigineFlag()), EduStudentEnroll::getAborigineFlag, vo.getAborigineFlag())
                .set(StringUtils.isNotBlank(vo.getSpecialFlag()), EduStudentEnroll::getSpecialFlag, vo.getSpecialFlag())
                .set(StringUtils.isNotBlank(vo.getFormId()), EduStudentEnroll::getFormId, vo.getFormId())
                .set(EduStudentEnroll::getRemarks, vo.getRemarks())
                .set(EduStudentEnroll::getParam20, vo.getParam20())
                .set(StringUtils.isNotBlank(vo.getBirthYmd()), EduStudentEnroll::getBirthYmd, vo.getBirthYmd())
                .set(StringUtils.isNotBlank(vo.getFatherIdcard()), EduStudentEnroll::getFatherIdcard, vo.getFatherIdcard())
                .set(StringUtils.isNotBlank(vo.getFatherCardType()), EduStudentEnroll::getFatherCardType, vo.getFatherCardType())
                .set(StringUtils.isNotBlank(vo.getFatherName()), EduStudentEnroll::getFatherName, vo.getFatherName())
                .set(StringUtils.isNotBlank(vo.getMotherCardType()), EduStudentEnroll::getMotherCardType, vo.getMotherCardType())
                .set(StringUtils.isNotBlank(vo.getMotherIdcard()), EduStudentEnroll::getMotherIdcard, vo.getMotherIdcard())
                .set(StringUtils.isNotBlank(vo.getMotherName()), EduStudentEnroll::getMotherName, vo.getMotherName())
                .set(StringUtils.isNotBlank(vo.getFatherCellphone()), EduStudentEnroll::getFatherCellphone, vo.getFatherCellphone())
                .set(StringUtils.isNotBlank(vo.getMotherCellphone()), EduStudentEnroll::getMotherCellphone, vo.getMotherCellphone())
                .set(StringUtils.isNotBlank(vo.getAddress()), EduStudentEnroll::getAddress, vo.getAddress())
        );

        //2.修改预采集信息，根据身份证进行查询
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EduStudentEnrollPre::getIdcard, eduStudentEnroll.getIdcard())
                .eq(EduStudentEnrollPre::getYear, eduStudentEnroll.getYear())
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType());
        List<EduStudentEnrollPre> eduStudentEnrollPres = eduStudentEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(eduStudentEnrollPres)) {
            for (EduStudentEnrollPre eduStudentEnrollPre : eduStudentEnrollPres) {
                eduStudentEnrollPreService.update(Wrappers.<EduStudentEnrollPre>lambdaUpdate()
                        .eq(EduStudentEnrollPre::getStudentEnrollPreId, eduStudentEnrollPre.getStudentEnrollPreId())
                        .set(EduStudentEnrollPre::getIdcard, vo.getIdcard())
                        .set(EduStudentEnrollPre::getCardType, vo.getCardType())
                        .set(EduStudentEnrollPre::getFullName, vo.getFullName())
                        .set(StringUtils.isNotBlank(vo.getFatherIdcard()), EduStudentEnrollPre::getFatherIdcard, vo.getFatherIdcard())
                        .set(StringUtils.isNotBlank(vo.getFatherCardType()), EduStudentEnrollPre::getFatherCardType, vo.getFatherCardType())
                        .set(StringUtils.isNotBlank(vo.getFatherName()), EduStudentEnrollPre::getFatherName, vo.getFatherName())
                        .set(StringUtils.isNotBlank(vo.getMotherCardType()), EduStudentEnrollPre::getMotherCardType, vo.getMotherCardType())
                        .set(StringUtils.isNotBlank(vo.getMotherIdcard()), EduStudentEnrollPre::getMotherIdcard, vo.getMotherIdcard())
                        .set(StringUtils.isNotBlank(vo.getMotherName()), EduStudentEnrollPre::getMotherName, vo.getMotherName())
                );
            }
        }

        //修改家庭表信息
        List<String> preIds = eduStudentEnrollPres.stream().map(EduStudentEnrollPre::getStudentEnrollPreId).distinct().collect(Collectors.toList());
        QueryWrapper<EduStudentEnrollFamily> familyQueryWrapper = new QueryWrapper<>();
        familyQueryWrapper.lambda().in(EduStudentEnrollFamily::getStudentEnrollPreId, preIds);
        List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(familyQueryWrapper);
        if (CollectionUtil.isNotEmpty(familyList)) {
            for (EduStudentEnrollFamily eduStudentEnrollFamily : familyList) {
                //父亲
                if (eduStudentEnrollFamily.getRelationshipType().equals(RelationTypeEnum.father.getType())) {
                    eduStudentEnrollFamilyService.update(Wrappers.<EduStudentEnrollFamily>lambdaUpdate()
                            .eq(EduStudentEnrollFamily::getStudentPreFamilyId, eduStudentEnrollFamily.getStudentPreFamilyId())
                            .set(StringUtils.isNotBlank(vo.getFatherIdcard()), EduStudentEnrollFamily::getIdcard, vo.getFatherIdcard())
                            .set(StringUtils.isNotBlank(vo.getFatherCardType()), EduStudentEnrollFamily::getCardType, vo.getFatherCardType())
                            .set(StringUtils.isNotBlank(vo.getFatherName()), EduStudentEnrollFamily::getFullName, vo.getFatherName())
                    );
                } else if (RelationTypeEnum.mother.getType().equals(eduStudentEnrollFamily.getRelationshipType())) {
                    eduStudentEnrollFamilyService.update(Wrappers.<EduStudentEnrollFamily>lambdaUpdate()
                            .eq(EduStudentEnrollFamily::getStudentPreFamilyId, eduStudentEnrollFamily.getStudentPreFamilyId())
                            .set(StringUtils.isNotBlank(vo.getMotherIdcard()), EduStudentEnrollFamily::getIdcard, vo.getMotherIdcard())
                            .set(StringUtils.isNotBlank(vo.getMotherCardType()), EduStudentEnrollFamily::getCardType, vo.getMotherCardType())
                            .set(StringUtils.isNotBlank(vo.getMotherName()), EduStudentEnrollFamily::getFullName, vo.getMotherName())
                    );
                }

            }

        }

        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
        return Convert.convert(EduStudentEnrollVO.class, vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJhJyj0042", title = "获取义务教育报名信息(教育局)", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getJyjYwBmApplyInfo(EduStudentEnrollQueryVO vo) {
        vo.setOpType("10");
        vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        if (eduHelper.thisAreaCode().equals(vo.getAreaCode())) {
            vo.setAreaCode(null);
        }
        if (BoolEnum.TRUE.getType().equals(vo.getXxllFlag())) {
            vo.setSource("6");
        }
        PageInfo<EduStudentEnrollVO> pageInfo = this.getList(vo);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0066", title = "报名线下核验材料核验", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0066",
            operationName = "报名线下核验材料核验",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void verificationAudit(EduStudentEnrollVerificationVO vo) {
        Integer year = eduHelper.thisYear();
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被回退，请重新查询");
        }
        if(!EnrollStatusFormalEnum.dsh.getType().equals(old.getEnrollStatus())&&!EnrollStatusFormalEnum.hy.getType().equals(old.getEnrollStatus())){
            throw new AppException(old.getFullName() + "的报名数据已审核，请重新查询");
        }
        if (BoolEnum.FALSE.getType().equalsIgnoreCase(old.getIcertificatioFlag())) {
            //待核验
            throw new AppException("该人员不需要核验，请刷新数据");
        }
        if (old.getYear() < year) {
            throw new AppException("历年报名数据不允许核验");
        }
        EnrollCheckShLqVO checkShLqVO = new EnrollCheckShLqVO();
        checkShLqVO.setYear(year);
        checkShLqVO.setAreaCode(vo.getAreaCode());
        checkShLqVO.setOpType(old.getSchoolNature());
        checkShLqVO.setSchoolId(old.getSchoolId());
        if ("0".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType(old.getSchoolNature());
        }
        if ("1".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType("1");
        }
        checkShLqVO.setIsJyj(false);
        ArrayList<EduStudentEnrollVerification> list = new ArrayList<>();
        checkSh(checkShLqVO);
        boolean updateFlag = false;
        if (!CollectionUtils.isEmpty(vo.getVerificationVOList())) {
            UpdateWrapper<EduStudentEnrollPre> preUpdateWrapper = new UpdateWrapper<>();
            preUpdateWrapper.lambda().eq(EduStudentEnrollPre::getIdcard, old.getIdcard())
                    .eq(EduStudentEnrollPre::getYear, old.getYear());
            for (EduStudentEnrollVerificationVO ver : vo.getVerificationVOList()) {
                ver.setVerificationUserId(SessionUtil.getUserId());
                ver.setVerificationTime(new Date());
                EduStudentEnrollVerification verification = Convert.convert(EduStudentEnrollVerification.class, ver);
                list.add(verification);
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(ver.getVerificationStatus())) {
                    //核验通过
                    if (VerificationTypeEnum.yzb.getType().equalsIgnoreCase(ver.getVerificationType())
                            || VerificationTypeEnum.fwq.getType().equalsIgnoreCase(ver.getVerificationType())
                            || VerificationTypeEnum.fhyz.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getHouseId, old.getHouseId())
                                .set(EduStudentEnrollPre::getHouseholdId, old.getHouseholdId())
                                .set(EduStudentEnrollPre::getConsistentType, "2")//人工核对
                                .set(EduStudentEnrollPre::getConsistentFlag, BoolEnum.TRUE.getType())
                                .set(EduStudentEnrollPre::getConsistentRemarks, "报名后线下人工核验")
                                .set(EduStudentEnrollPre::getConsistentTime, new Date())
                                .set(EduStudentEnrollPre::getConsistentUserId, SessionUtil.getUserId());
                        updateFlag = true;
                    }
                    if (VerificationTypeEnum.yzb.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getAborigineFlag, BoolEnum.TRUE.getType());
                    }
                    if (VerificationTypeEnum.fwq.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getServiceAreaFlag, BoolEnum.TRUE.getType());
                    }
                    if (VerificationTypeEnum.qzgx.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getFamilyFlag, BoolEnum.TRUE.getType())
                                .set(EduStudentEnrollPre::getFamilyType, "2")
                                .set(EduStudentEnrollPre::getFamilyRemark, "报名后线下人工核验");
                        updateFlag = true;
                    }
                }
            }
            if (updateFlag) {
                eduStudentEnrollPreService.update(preUpdateWrapper);
            }

        }
        StudentEnrollSaveVO studentEnrollSaveVO = new StudentEnrollSaveVO();
        studentEnrollSaveVO.setStudentEnrollId(vo.getStudentEnrollId());
        UpdateWrapper<EduStudentEnroll> updateWrapper = new UpdateWrapper<EduStudentEnroll>();
        if (vo.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hybtg.getType())) {
            //当核验不通过时：enrollStatus 设置为9 审核状态设置为审核不通过,录取状态设置为0 不予录取
            updateWrapper.lambda().set(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.hybtg.getType())
                    .set(EduStudentEnroll::getAuthStatus, AuthStatusEnum.NO.getType())
                    .set(EduStudentEnroll::getAdmitFlag, BoolEnum.FALSE.getType());
            //核验不通过，调用初审不通过
            studentEnrollSaveVO.setAuthStatus(AuthStatusEnum.NO.getType());
            studentEnrollSaveVO.setAuthRemarks(vo.getAuthRemarks());
            studentEnrollSaveVO.setAspirationType(vo.getAspirationType());
            this.auth(studentEnrollSaveVO);
            //删除录取表，删除审核表 删除报名表
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("3");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("2");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("1");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        }
        if (vo.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hytg.getType())) {
            updateWrapper.lambda().set(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dsh.getType());
            studentEnrollSaveVO.setAuthStatus(AuthStatusEnum.YES.getType());
        }
        updateWrapper.lambda().set(EduStudentEnroll::getIcertificatioFlag, vo.getIcertificatioFlag())
                .eq(EduStudentEnroll::getStudentEnrollId, old.getStudentEnrollId());
        eduStudentEnrollService.update(updateWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            //更新校验表
            eduStudentEnrollVerificationService.updateBatchById(list);
        }
        //审核通过，调用初审通过
        if (vo.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hytg.getType())) {
            studentEnrollSaveVO.setAuthRemarks(vo.getAuthRemarks());
            studentEnrollSaveVO.setAspirationType(vo.getAspirationType());
            this.auth(studentEnrollSaveVO);
        }
        //清除缓存
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(old.getMotherIdcard());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0036", title = "获取义务教育民办第一志愿报名列表信息", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getYwMbApplyInfo(EduStudentEnrollQueryVO vo) {
        vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        vo.setOpType("1");
        PageInfo<EduStudentEnrollVO> pageInfo = this.getYwApplyList(vo);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0025", title = "获取义务教育民转公报名列表信息", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollVO> getYwMzgApplyInfo(EduStudentEnrollQueryVO vo) {
        vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        vo.setOpType("2");

        PageInfo<EduStudentEnrollVO> pageInfo = this.getYwApplyList(vo);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0067", title = "报名学校批量初审", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0067",
            operationName = "报名批量审核",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywAuthBatch(StudentEnrollSaveVO vo) {
        if (!CollectionUtils.isEmpty(vo.getStudentEnrollIdList())) {
            for (String studentEnrollId : vo.getStudentEnrollIdList()) {
                LambdaQueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<EduStudentEnroll>().lambda().eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                        .eq(EduStudentEnroll::getYear, eduHelper.thisYear());
                List<EduStudentEnroll> eduStudentEnrolls = eduStudentEnrollService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrolls)) {
                    if (!eduStudentEnrolls.get(0).getEnrollStatus().equals(EnrollStatusFormalEnum.dsh.getType())) {
                        throw new AppException("存在待核验(大数据匹配未通过)的数据或该学生状态不是待审核(大数据核验通过)状态");
                    }
                    StudentEnrollSaveVO authVO = new StudentEnrollSaveVO();
                    authVO.setAuthStatus(vo.getAuthStatus());
                    authVO.setAuthRemarks(vo.getAuthRemarks());
                    authVO.setStudentEnrollId(studentEnrollId);
                    this.auth(authVO);
                }
            }
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0068", title = "报名学校批量复审", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0068",
            operationName = "报名学校批量复审",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywReviewAuthBatch(StudentEnrollSaveVO vo) {
        if (!CollectionUtils.isEmpty(vo.getStudentEnrollIdList())) {
            if (vo.getStudentEnrollIdList().size() > 100) {
                throw new AppException("批量审核数量不能大于100条");
            }
            for (String studentEnrollId : vo.getStudentEnrollIdList()) {
                LambdaQueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<EduStudentEnroll>().lambda().eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                        .eq(EduStudentEnroll::getYear, eduHelper.thisYear());
                List<EduStudentEnroll> eduStudentEnrolls = eduStudentEnrollService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrolls)) {
                    if (!eduStudentEnrolls.get(0).getEnrollStatus().equals(EnrollStatusFormalEnum.dlq.getType())) {
                        throw new AppException("存在未初审核通过的数据");
                    }
                    StudentEnrollSaveVO authVO = new StudentEnrollSaveVO();
                    authVO.setAuthStatus(vo.getAuthStatus());
                    authVO.setAuthRemarks(vo.getAuthRemarks());
                    authVO.setStudentEnrollId(studentEnrollId);
                    this.review(authVO);
                }
            }
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0069", title = "获取参保缴费详情", funcType = FuncTypeEnum.query, publicFlag = BoolEnum.TRUE)
    public PageInfo<EduSocialSecurityDetailVO> getSocialSecurityDetail(EduSocialSecurityQueryVO vo) {
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            vo.setPageNum(0);
            vo.setPageSize(100);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        LambdaQueryWrapper<EduSocialSecurityDetail> queryWrapper = new QueryWrapper<EduSocialSecurityDetail>().lambda().eq(EduSocialSecurityDetail::getSocialSecurityId, vo.getSocialSecurityId());
        List<EduSocialSecurityDetail> list = eduSocialSecurityDetailService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduSocialSecurityDetail> pageInfo = new PageInfo<>(list);
        List<EduSocialSecurityDetailVO> resultList = Convert.toList(EduSocialSecurityDetailVO.class, list);
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0070", title = "根据报名id修改加报名类别", funcType = FuncTypeEnum.update, checkPrivilege = BoolEnum.FALSE)
    @Transactional
    public void updateConfigNameByEnrollId(EduConfigNameAliasVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getConfigNameAlias())) {
            throw new AppException("报名类别别名不能为空");
        }
        if (StringUtils.isBlank(vo.getConfigName())) {
            throw new AppException("报名类别不能为空");
        }
        if (StringUtils.isBlank(vo.getFormId())) {
            throw new AppException("报名表单id不能为空");
        }
        EduStudentEnroll enroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (ObjectUtils.isEmpty(enroll)) {
            throw new AppException("学生报名信息不存在！");
        }
        List<String> enrollStatus = new ArrayList<>();
        enrollStatus.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatus.add(EnrollStatusFormalEnum.hy.getType());
        if (!enrollStatus.contains(enroll.getEnrollStatus())) {
            throw new AppException("只有待审核/待核验的数据才能降级！");
        }


        UpdateWrapper<EduStudentEnroll> enrollUpdateWrapper = new UpdateWrapper<>();
        enrollUpdateWrapper.lambda().eq(EduStudentEnroll::getStudentEnrollId, vo.getStudentEnrollId())
                .set(EduStudentEnroll::getConfigName, vo.getConfigName())
                .set(EduStudentEnroll::getConfigNameAlias, vo.getConfigNameAlias())
                .set(EduStudentEnroll::getAuthRemarks, vo.getAuthRemarks())
                .set(EduStudentEnroll::getRemarks, enroll.getConfigNameAlias() + "降级为" + vo.getConfigNameAlias() + ":原因" + vo.getAuthRemarks())
                .set(EduStudentEnroll::getFormId, vo.getFormId());

        //根据不同的报名类别去设置服务区原住民的状态
        if (vo.getConfigNameAlias().equals(ConfigNameAliasEnum.yzm.getName())){
            enrollUpdateWrapper.lambda()
                    .set(EduStudentEnroll::getAborigineFlag, BoolEnum.TRUE.getType())
                    .set(EduStudentEnroll::getServiceFlag, BoolEnum.FALSE.getType());
        }else if (vo.getConfigNameAlias().equals(ConfigNameAliasEnum.fwqyzm.getName())){
            enrollUpdateWrapper.lambda()
                    .set(EduStudentEnroll::getAborigineFlag, BoolEnum.TRUE.getType())
                    .set(EduStudentEnroll::getServiceFlag, BoolEnum.TRUE.getType());
        }else if (vo.getConfigNameAlias().equals(ConfigNameAliasEnum.fwq.getName())){
            enrollUpdateWrapper.lambda()
                    .set(EduStudentEnroll::getAborigineFlag, BoolEnum.FALSE.getType())
                    .set(EduStudentEnroll::getServiceFlag, BoolEnum.TRUE.getType());
        }else {
            enrollUpdateWrapper.lambda()
                    .set(EduStudentEnroll::getAborigineFlag, BoolEnum.FALSE.getType())
                    .set(EduStudentEnroll::getServiceFlag, BoolEnum.FALSE.getType());
        }
        eduStudentEnrollService.update(enrollUpdateWrapper);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0071", title = "学校补充材料", funcType = FuncTypeEnum.update, checkPrivilege = BoolEnum.FALSE)
    public void upSchoolFileById(EduEnrollSchoolFileVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (eduStudentEnroll == null) {
            throw new AppException("未找到报名信息");
        }
        if (!eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.dsh.getType()) &&
                !eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.dlq.getType()) &&
                !eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.hy.getType())) {
            throw new AppException("当前不在审核中，不能上传材料");
        }
        UpdateWrapper<EduStudentEnroll> enrollUpdateWrapper = new UpdateWrapper<>();
        enrollUpdateWrapper.lambda().eq(EduStudentEnroll::getStudentEnrollId, vo.getStudentEnrollId())
                .set(EduStudentEnroll::getParam20, vo.getParam20());
        eduStudentEnrollService.update(enrollUpdateWrapper);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0072", title = "学校选择房产", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0072",
            operationName = "学校选择房产",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    public void schoolChooseHouse(EduEnrollSchoolChooseHouseVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getHouseId())) {
            throw new AppException("房产不能为空");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (eduStudentEnroll == null) {
            throw new AppException("未找到报名信息");
        }
        if (!eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.dsh.getType()) &&
                !eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.dlq.getType()) &&
                !eduStudentEnroll.getEnrollStatus().equals(EnrollStatusFormalEnum.hy.getType())) {
            throw new AppException("当前不在审核中，不能修改房产");
        }
        if (StringUtils.isBlank(eduStudentEnroll.getParam5())) {
            eduStudentEnroll.setParam5(eduStudentEnroll.getHouseId());
            if (eduStudentEnroll.getHouseId().equals(vo.getHouseId())) {
                throw new AppException("当前已经是选择的这套房产！");
            }
        } else {
            if (eduStudentEnroll.getParam5().equals(vo.getHouseId())) {
                throw new AppException("当前已经是选择的这套房产！");
            }
        }

        eduStudentEnroll.setHouseId(vo.getHouseId());
        EduHouse house = eduHouseService.getById(vo.getHouseId());
        if (house == null) {
            throw new AppException("房产信息不存在");
        }
        if (house.getStatus().equals(BoolEnum.FALSE.getType())) {
            throw new AppException("无效房产不能选择");
        }

        if (StringUtils.isNotBlank(house.getPrimarySchoolOne())) {
            Double p = Double.parseDouble(house.getPrimarySchoolOne().replaceAll("%", ""));
            if (p < 50) {
                throw new AppException("房产份额小于50%，不能选择");
            }
        }
        if (SchoolNatureEnum.gb.getType().equals(eduStudentEnroll.getSchoolNature())) {
            //判断是否在学区范围内
            if (StringUtils.isBlank(house.getAddressId())) {
                throw new AppException("地址未解析，请联系系统管理员");
            }
            QueryWrapper<EduAddressSchool> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduAddressSchool::getSchoolId, eduStudentEnroll.getSchoolId())
                    .eq(EduAddressSchool::getAddressId, house.getAddressId());
            if (eduAddressSchoolService.count(queryWrapper) <= 0) {
                throw new AppException("该地址不在学校学区范围内，请先去学校学区管理进行关联");
            }
        }
        eduStudentEnroll.setHouseAdreess(house.getAddress());
        eduStudentEnroll.setRealProperty(house.getRealProperty());
        eduStudentEnroll.setRealPropertyNum(house.getRealPropertyNum());
        eduStudentEnroll.setRegisterDate(house.getRegisterDate());
        eduStudentEnroll.setQlrName(house.getQlrName());
        eduStudentEnrollService.updateById(eduStudentEnroll);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0073", title = "民办学校批量录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0073",
            operationName = "民办学校批量录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void mbBatchAdmission(StudentEnrollSaveVO vo) {
        if (!CollectionUtils.isEmpty(vo.getStudentEnrollIdList())) {
            for (String studentEnrollId : vo.getStudentEnrollIdList()) {
                LambdaQueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<EduStudentEnroll>().lambda().eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                        .eq(EduStudentEnroll::getYear, eduHelper.thisYear());
                List<EduStudentEnroll> eduStudentEnrolls = eduStudentEnrollService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrolls)) {
                    if (!eduStudentEnrolls.get(0).getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType())) {
                        throw new AppException("存在未复审通过的数据");
                    }
                    StudentEnrollSaveVO admitVO = new StudentEnrollSaveVO();
                    admitVO.setAdmitFlag(vo.getAdmitFlag());
                    admitVO.setAdmitRemarks(vo.getAdmitRemarks());
                    admitVO.setStudentEnrollId(studentEnrollId);
                    this.admit(admitVO);
                }
            }
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0074", title = "民转公学校批量录取", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0074",
            operationName = "民转公学校批量录取",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void mzgBatchAdmission(StudentEnrollSaveVO vo) {
        if (!CollectionUtils.isEmpty(vo.getStudentEnrollIdList())) {
            for (String studentEnrollId : vo.getStudentEnrollIdList()) {
                LambdaQueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<EduStudentEnroll>().lambda().eq(EduStudentEnroll::getStudentEnrollId, studentEnrollId)
                        .eq(EduStudentEnroll::getYear, eduHelper.thisYear());
                List<EduStudentEnroll> eduStudentEnrolls = eduStudentEnrollService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrolls)) {
                    if (!eduStudentEnrolls.get(0).getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType())) {
                        throw new AppException("存在未复审通过的数据");
                    }
                    StudentEnrollSaveVO admitVO = new StudentEnrollSaveVO();
                    admitVO.setAdmitFlag(vo.getAdmitFlag());
                    admitVO.setAdmitRemarks(vo.getAdmitRemarks());
                    admitVO.setStudentEnrollId(studentEnrollId);
                    this.admit(admitVO);
                }
            }
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0075", title = "义务教育报名信息导出(管理员/教育局)", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void exportEnrollInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        vo.setOpType("0");
        if (vo.getYear() == null) {
            throw new AppException("招生年度不能为空");
        }
        if (BoolEnum.TRUE.getType().equals(vo.getXxllFlag())) {
            vo.setSource("6");
        }
        this.exportApplyInfo(vo, response);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0079", title = "义务教育报名一键退回到待审核(学校退回)", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0079",
            operationName = "义务教育报名一键退回到待审核(学校退回)",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywApplySchoolBackAuth(EduStudentEnrollKeyVO vo) {
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        //如果是学校账号，只能退回资料审核不通过，待教育局复审，不予录取的数据
        String orgId = SessionUtil.getOrgId();
        EduSchoolVO schoolInfo = eduSchoolService.getDetail(orgId);

        if (ObjectUtils.isEmpty(schoolInfo)) {
            throw new AppException("当前功能是学校退回，学校信息不存在");
        }
        //学校允许退回的状态
        List<String> schoolBackStatus = new ArrayList<>();
        schoolBackStatus.add(EnrollStatusFormalEnum.dlq.getType());
        schoolBackStatus.add(EnrollStatusFormalEnum.hybtg.getType());
        if (schoolBackStatus.contains(old.getEnrollStatus())) {
            this.backAuth(vo);
        } else if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.ywblq.getType())) {
            //如果要退回的是业务不予录入 并且是教育局操作的
            QueryWrapper<EduStudentEnrollReview> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnrollReview::getStudentEnrollId, vo.getStudentEnrollId())
                    .eq(EduStudentEnrollReview::getAuditType, "2");
            //如果没有教育局操作过，允许退回
            if (eduStudentEnrollReviewService.count(queryWrapper) == 0) {
                this.backAuth(vo);
            } else {
                throw new AppException("学校不能退回教育局审核不通过的数据！");
            }
        }

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0080", title = "义务教育报名一键退回到待审核(教育局退回)", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollJh0080",
            operationName = "义务教育报名一键退回到待审核(教育局退回)",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void ywApplyJyjBackAuth(EduStudentEnrollKeyVO vo) {
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        //教育局不能退回录取数据
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.lq.getType())) {
            throw new AppException("不能退回录取数据");
        }
        this.backAuth(vo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0082", title = "根据报名时间控制小学初中报名审核权限", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE)
    public Boolean primaryAndJuniorAuthPower(EduStudentEnrollPreKeyVO vo) {
        if(StringUtils.isBlank(vo.getSchoolId())){
            vo.setSchoolId(SessionUtil.getSessionInfo().getOrgId());
        }
        if (StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        //判断是否在年度招生时间中
        EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setYear(eduHelper.thisYear());
        EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
        if(eduOperationCacheVO==null){
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO bmOperation=operation.get("YW002");//第一批
        EduOperationCacheDetailVO bbOperation=operation.get("YW022");//第二批
        EduOperationCacheDetailVO qbOperation=operation.get("YW010");//第三批
        EduOperationCacheDetailVO bmxxOperation=operation.get("YW066");//第一批小学报名业务期
        EduOperationCacheDetailVO bmczOperation=operation.get("YW067");//第一批初中报名业务期
        EduOperationCacheDetailVO bbxxOperation=operation.get("YW068");//第二批小学报名业务期
        EduOperationCacheDetailVO bbczOperation=operation.get("YW069");//第二批初中报名业务期
        EduOperationCacheDetailVO qbxxOperation=operation.get("YW070");//第三批小学报名业务期
        EduOperationCacheDetailVO qbczOperation=operation.get("YW071");//第三批初中报名业务期
        EduOperationCacheDetailVO bbTwoOperation = operation.get("YW072");//第二批第二次
        EduOperationCacheDetailVO bbTwoXxOperation = operation.get("YW073");//第二批小学第二次
        EduOperationCacheDetailVO bbTwoCzOperation = operation.get("YW074");//第二批初中第二次

        //判断是否报名业务期
        boolean bmFlag = bmOperation==null?false:bmOperation.isFlag();
        boolean bmxxFlag = bmxxOperation==null?false:bmxxOperation.isFlag();
        boolean bmczFlag = bmczOperation==null?false:bmczOperation.isFlag();
        //判断是否补报业务期
        boolean bbFlag = bbOperation==null?false:bbOperation.isFlag();
        boolean bbxxFlag = bbxxOperation==null?false:bbxxOperation.isFlag();
        boolean bbczFlag = bbczOperation==null?false:bbczOperation.isFlag();
        //第二批次第二次
        boolean bbTwoFlag = bbTwoOperation == null ? false : bbTwoOperation.isFlag();
        boolean bbxxTwoFlag = bbTwoXxOperation == null ? false : bbTwoXxOperation.isFlag();
        boolean bbczTwoFlag = bbTwoCzOperation == null ? false : bbTwoCzOperation.isFlag();

        //判断是否空额抢报业务期
        boolean qbFlag = qbOperation==null?false:qbOperation.isFlag();
        boolean qbxxFlag = qbxxOperation==null?false:qbxxOperation.isFlag();
        boolean qbczFlag = qbczOperation==null?false:qbczOperation.isFlag();
        EduSchoolVO serviceDetail = eduSchoolService.getDetail(vo.getSchoolId());
        boolean canNotAuth=false;
        //如果该学校处于当前批次报名时间内，不允许审核
        if (serviceDetail.getSchoolCategory().equals(SchoolCategoryEnum.JUNIOR.getType())){
            //如果是第一轮报名并且是初中报名阶段
            if (bmFlag&&bmczFlag){
                canNotAuth=true;
            }
            if (bbFlag&&bbczFlag){
                canNotAuth=true;
            }
            if (bbTwoFlag&&bbczTwoFlag){
                canNotAuth=true;
            }
            if (qbFlag&&qbczFlag){
                canNotAuth=true;
            }
        }else if (serviceDetail.getSchoolCategory().equals(SchoolCategoryEnum.PRIMARY.getType())){
            if (bmFlag&&bmxxFlag){
                canNotAuth=true;
            }
            if (bbFlag&&bbxxFlag){
                canNotAuth=true;
            }
            if (bbTwoFlag&&bbxxTwoFlag){
                canNotAuth=true;
            }
            if (qbFlag&&qbxxFlag){
                canNotAuth=true;
            }
        }
        return canNotAuth;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollJh0083", title = "判断用户报名区划", funcType = FuncTypeEnum.query)
    public UserAreaVO getEnrollArea(EduStudentEnrollPreKeyVO vo) {
        SessionInfo sessionInfo = SessionUtil.getSessionInfo();
        String idcard=null;
        if (sessionInfo.getIdcard()!=null){
            idcard=sessionInfo.getIdcard();
        }
        UserAreaVO userAreaVO = new UserAreaVO();
        boolean flag=false;
        Integer year = eduHelper.thisYear();
        List<String> showAllAreaCode=new ArrayList<>();
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("showAllAreaCode");
        String showAllParams = commonIntegration.getValueByKey(commonVO);
        userAreaVO.setIsOnlyShow(showAllParams);
        List<String> areaCodeList = Arrays.stream(showAllParams.split(",")).collect(Collectors.toList());
        if (StringUtils.isNotBlank(idcard)){
            LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<EduStudentEnrollPre>()
                    .lambda()
                    .select(EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getAreaCode)
                    .eq(EduStudentEnrollPre::getYear,year)
                    .eq(EduStudentEnrollPre::getAuthStatus,AuthStatusEnum.YES.getType())
                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                    .or().eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                    .or().eq(EduStudentEnrollPre::getMotherIdcard, idcard);
            List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(queryWrapper);
            for (EduStudentEnrollPre pre : preList){
                if (StringUtils.isNotBlank(pre.getAreaCode())){
                    if (areaCodeList.contains(pre.getAreaCode())){
                        flag=true;
                        showAllAreaCode.add(pre.getAreaCode());
                    }
                }
                if (StringUtils.isNotBlank(pre.getIdcard())&&StringUtils.isBlank(pre.getAreaCode())){
                    LambdaQueryWrapper<EduHousehold> householdLambdaQueryWrapper = new QueryWrapper<EduHousehold>().lambda()
                            .select(EduHousehold::getAreaCode, EduHousehold::getAddressId)
                            .eq(EduHousehold::getIdcard, pre.getIdcard())
                            .eq(EduHousehold::getYear, year)
                            .eq(EduHousehold::getStatus, "1");
                    EduHousehold household = eduHouseholdService.getOne(householdLambdaQueryWrapper, false);
                    if (household!=null){
                        if (StringUtils.isNotBlank(household.getAreaCode())){
                            if (areaCodeList.contains(household.getAreaCode())){
                                flag=true;
                                showAllAreaCode.add(household.getAreaCode());
                            }
                        }
                        if (StringUtils.isNotBlank(household.getAddressId())&&StringUtils.isBlank(household.getAreaCode())){
                            LambdaQueryWrapper<EduAddress> addressLambdaQueryWrapper = new QueryWrapper<EduAddress>().lambda()
                                    .select(EduAddress::getAreaCode)
                                    .eq(EduAddress::getAddressId, household.getAddressId())
                                    .eq(EduAddress::getYear, year);
                            EduAddress address = eduAddressService.getOne(addressLambdaQueryWrapper, false);
                            if (StringUtils.isNotBlank(address.getAreaCode())){
                                if (areaCodeList.contains(address.getAreaCode())){
                                    flag=true;
                                    showAllAreaCode.add(pre.getAreaCode());
                                }
                            }
                        }
                    }
                }
            }
        }
        List<String> stringList = showAllAreaCode.stream().distinct().collect(Collectors.toList());
        userAreaVO.setShowAllAreaCode(stringList);
        userAreaVO.setFlag(flag);
        return userAreaVO;
    }
    /**
     * 管理员导出学生报名信息
     *
     * @param vo
     * @param response
     */
    private void exportApplyInfo(EduStudentEnrollQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setDataexportApplyInfo(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    /**
     * 设置导出的excel数据
     *
     * @param excelModelVO
     * @param excelWriter
     * @param destFilePath
     * @param vo
     * @param pageNum
     */
    private void setDataexportApplyInfo(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentEnrollQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            vo.setDesensitizeFlag(false);
            PageInfo<EduStudentEnrollVO> pageInfo = getApplyList(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Object> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentEnrollVO eduStudentEnrollVO : pageInfo.getList()) {
                    list.add(eduStudentEnrollVO);
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeBean(excelWriter, list);
            } else {
                excelCommonHelper.writeBean(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setDataexportApplyInfo(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    /**
     * 查询导出的数据
     *
     * @param vo
     * @return
     */
    private PageInfo<EduStudentEnrollVO> getApplyList(EduStudentEnrollQueryVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("查询年度不能空");
        }
        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            String orderBy = "";
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    orderBy = orderBy + ",";
                    if (orderVO.getProperty().equals("registerDate")) {
                        orderBy = orderBy + "a.";
                    } else if (orderVO.getProperty().equals("qysj")) {
                        orderBy = orderBy + "a.";
                    } else {
                        orderBy = orderBy + "a.";
                    }
                    orderBy = orderBy + StrUtil.toUnderlineCase(orderVO.getProperty()) + " " + orderVO.getOrder();
                }
            }
            vo.setOrderBy(orderBy);

        }

        List<EduStudentEnrollVO> list;
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),STUDENT_ENROLL_TABLE);
        if (!queryHistoryFlag) {
            // 开启分页
            if (vo.getPageNum() != null && vo.getPageSize() != null) {
                PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            }
             list = eduStudentEnrollService.getYwApplyList(vo);
        }else {
            Boolean encryptFlag = eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_ENROLL_TABLE);
            if (encryptFlag){
                eduStudentEnrollService.queryEncrypt(vo);
            }
            // 开启分页
            if (vo.getPageNum() != null && vo.getPageSize() != null) {
                PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            }
             list = eduhStudentEnrollService.getYwApplyListYq(vo);
            //解密
            for (EduStudentEnrollVO studentEnrollVO : list) {
                if ("1".equals(studentEnrollVO.getEncryptFlag())){
                    eduStudentEnrollService.decrypt(studentEnrollVO);
                }
            }
        }
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        Boolean desensitizeFlag = vo.getDesensitizeFlag();

        // 不为空则获取分页结果
        PageInfo<EduStudentEnrollVO> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollVO> resultList = pageInfo.getList();
        dictHelper.valueToName(resultList, Arrays.asList(EduYwEnrollDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getAreaCode, a -> a, (k1, k2) -> k1));
        boolean flag = false;
        Map<String, EduStudentEnroll> map = new HashMap<>();
        //获取报名id
        List<String> enrollIdList = resultList.stream().map(EduStudentEnrollVO::getStudentEnrollId).distinct().collect(Collectors.toList());
        List<String> authStatusList = new ArrayList<>();
        authStatusList.add(AuthStatusEnum.NODO.getType());
        authStatusList.add(AuthStatusEnum.YES.getType());
        QueryWrapper<EduStudentEnrollInvalid> invalidQueryWrapper = new QueryWrapper<>();
        invalidQueryWrapper.lambda()
                .select(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus)
                .in(EduStudentEnrollInvalid::getStudentEnrollId, enrollIdList)
                .in(EduStudentEnrollInvalid::getAuthStatus, authStatusList);
        List<EduStudentEnrollInvalid> invalidList = eduStudentEnrollInvalidService.list(invalidQueryWrapper);
        Map<String, String> collectMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(invalidList)) {
            collectMap = invalidList.stream().collect(Collectors.toMap(EduStudentEnrollInvalid::getStudentEnrollId, EduStudentEnrollInvalid::getAuthStatus));
        }
        //获取学生证件号码
        List<String> idcardList = resultList.stream().map(EduStudentEnrollVO::getIdcard).distinct().collect(Collectors.toList());
        Map<String, String> householdMap = new HashMap<>();
        Boolean householdHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_HOUSEHOLD);
        if (!householdHistoryFlag) {
            QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
            householdQueryWrapper.lambda().in(EduHousehold::getIdcard, idcardList)
                    .eq(EduHousehold::getYear, vo.getYear())
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType());
            List<EduHousehold> householdList = eduHouseholdService.list(householdQueryWrapper);
            if (!CollectionUtils.isEmpty(householdList)) {
                householdMap = householdList.stream().collect(Collectors.toMap(EduHousehold::getIdcard, EduHousehold::getAddress, (k1, k2) -> k1));
            }
        }else {
            Boolean encryptFlag = eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_HOUSEHOLD);
            QueryWrapper<EduhHousehold> eduhHouseholdQueryWrapper = new QueryWrapper<>();
            eduhHouseholdQueryWrapper.lambda()
                    .eq(EduhHousehold::getYear, vo.getYear())
                    .eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType());
            if (encryptFlag) {
                //加密身份证
                ArrayList<String> idcardListEncrypt = new ArrayList<>();
                for (String idCard : idcardList) {
                    idcardListEncrypt.add(CommonSecureUtil.sm4Encrypt(idCard));
                }
                eduhHouseholdQueryWrapper.lambda().in(EduhHousehold::getIdcard, idcardListEncrypt);
            } else {
                eduhHouseholdQueryWrapper.lambda().in(EduhHousehold::getIdcard, idcardList);
            }
            List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(eduhHouseholdQueryWrapper);
            //解密
            for (EduhHousehold eduhHousehold : eduhHouseholdList) {
                if ("1".equals(eduhHousehold.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhHousehold.getIdcard())) {
                        eduhHousehold.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getFullName())) {
                        eduhHousehold.setFullName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getFullName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getBeforeName())) {
                        eduhHousehold.setBeforeName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getBeforeName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getAddress())) {
                        eduhHousehold.setAddress(CommonSecureUtil.sm4Decrypt(eduhHousehold.getAddress()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholdPlace())) {
                        eduhHousehold.setHouseholdPlace(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholdPlace()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholder())) {
                        eduhHousehold.setHouseholder(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholder()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholderIdcard())) {
                        eduhHousehold.setHouseholderIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholderIdcard()));
                    }
                }
                householdMap = eduhHouseholdList.stream().collect(Collectors.toMap(EduhHousehold::getIdcard, EduhHousehold::getAddress, (k1, k2) -> k1));
            }
        }

        Integer year = eduHelper.thisYear();
        if (desensitizeFlag == null) {
            desensitizeFlag = true;
        }
        for (EduStudentEnrollVO studentEnroll : resultList) {
            if (SchoolNatureEnum.mzg.getType().equalsIgnoreCase(studentEnroll.getSchoolNature())) {
                studentEnroll.setHasHousehold(false);
                studentEnroll.setHasHouse(false);
                EduStudentEnroll enroll = map.get(studentEnroll.getIdcard());
                if (enroll != null) {
                    if ("A".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(true);
                        studentEnroll.setRegisterDate(null);
                    } else if ("B".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(false);
                        studentEnroll.setRegisterDate(null);
                    } else if ("C".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(false);
                        studentEnroll.setHasHouse(true);
                        if (householdMap.containsKey(studentEnroll.getIdcard())) {
                            studentEnroll.setHasHousehold(true);
                            if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                                studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                            }
                        } else {
                            studentEnroll.setHasHousehold(false);
                        }
                    } else if ("特殊户口".equalsIgnoreCase(enroll.getConfigName())) {
                        studentEnroll.setHasHousehold(true);
                        studentEnroll.setHasHouse(false);
                    } else {
                        if (householdMap.containsKey(studentEnroll.getIdcard())) {
                            studentEnroll.setHasHousehold(true);
                            if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                                studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                            }
                        } else {
                            studentEnroll.setHasHousehold(false);
                        }

                    }
                }
            } else if (SchoolNatureEnum.mb.getType().equalsIgnoreCase(studentEnroll.getSchoolNature())) {
                if (StringUtils.isBlank(studentEnroll.getHouseholdAddress())) {
                    studentEnroll.setHouseholdAddress(householdMap.get(studentEnroll.getIdcard()));
                }
                if (!BoolEnum.TRUE.getType().equalsIgnoreCase(studentEnroll.getFollowingFlag())) {
                    if (householdMap.containsKey(studentEnroll.getIdcard())) {
                        studentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                    }
                }
            }
            studentEnroll.setDelStatus(collectMap.get(studentEnroll.getStudentEnrollId()));

            if (!flag && EnrollStatusFormalEnum.dlq.getType().equals(studentEnroll.getEnrollStatus())) {
                flag = true;
                studentEnroll.setFirstFlag(true);
            } else {
                studentEnroll.setFirstFlag(false);
            }
            //设置街道
            if (!ObjectUtils.isEmpty(areaMap.get(studentEnroll.getStreet()))) {
                studentEnroll.setStreetName(areaMap.get(studentEnroll.getStreet()).getAreaName());
            }
            if (StringUtils.isBlank(studentEnroll.getAdmitFlag())) {
                studentEnroll.setAdmitFlag("2");
                studentEnroll.setAdmitFlagName("待录取");
            } else {
                if (BoolEnum.TRUE.getType().equals(studentEnroll.getAdmitFlag())) {
                    studentEnroll.setAdmitFlagName("已录取");
                } else {
                    studentEnroll.setAdmitFlagName("不予录取");
                }
            }
            if (BoolEnum.TRUE.getType().equals(studentEnroll.getSpecialFlag())) {
                studentEnroll.setSpecialFlagName("是");
            } else {
                studentEnroll.setSpecialFlagName("否");
            }
            if (StringUtils.isNotBlank(studentEnroll.getEnrollStatus())) {
                EnrollStatusFormalEnum formalEnum = EnrollStatusFormalEnum.getByType(studentEnroll.getEnrollStatus());
                studentEnroll.setEnrollStatusName(formalEnum == null ? "未知状态" : formalEnum.getName());
            } else {
                studentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
                studentEnroll.setEnrollStatusName(EnrollStatusFormalEnum.dsh.getName());
            }

            if (StringUtils.isBlank(studentEnroll.getConfigNameAlias())) {
                studentEnroll.setConfigNameAlias(studentEnroll.getConfigName());
            }
            if (desensitizeFlag) {
                if (!EnrollStatusFormalEnum.lq.getType().equalsIgnoreCase(studentEnroll.getEnrollStatus())) {
                    //录取不脱敏 其他都脱敏
                    EduDesensitizeUtil.desensitizeStudentEnroll(studentEnroll);
                }
            }
        }
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }


    /**
     * 义务端学校录入报名人员保存校验
     *
     * @param vo
     */
    private void saveCheckStudentEnroll(SaveStudentEnrollVO vo) {
        if (vo.getManagerFlag() == null) {
            vo.setManagerFlag(false);
        }
        if (StringUtils.isBlank(vo.getConfigTypeName()) && StringUtils.isBlank(vo.getConfigName())) {
            throw new AppException("报名类别不能为空");
        }
        if (StringUtils.isBlank(vo.getRemarks())) {
            throw new AppException("请输入录取依据");
        }
        if (!vo.getManagerFlag() && StringUtils.isBlank(vo.getParam20())) {
            throw new AppException("必须传入佐证资材料");
        }
        boolean xsFlag = IdcardUtil.isValidCard(vo.getIdcard());
        if (vo.getCardType().equals(CardTypeEnum.idcard.getType()) && !xsFlag) {
            throw new AppException("学生身份证有误！");
        } else {
            if (xsFlag && !CardTypeEnum.idcard.getType().equals(vo.getCardType())) {
                throw new AppException("学生证件类型，请选择身份证！");
            }
            vo.setIdcard(vo.getIdcard().trim().toUpperCase());
        }
        if (StringUtils.isBlank(vo.getMotherCardType())) {
            vo.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(vo.getFatherCardType())) {
            vo.setFatherCardType(CardTypeEnum.idcard.getType());
        }

        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        boolean flag = true;
        if (StringUtils.isNotBlank(vo.getMotherIdcard())) {
            boolean motherFlag = IdcardUtil.isValidCard(vo.getMotherIdcard());
            if (CardTypeEnum.idcard.getType().equals(vo.getMotherCardType()) && !motherFlag) {
                throw new AppException("母亲身份证有误！");
            } else {
                if (motherFlag && !CardTypeEnum.idcard.getType().equals(vo.getMotherCardType())) {
                    throw new AppException("母亲证件类型，请选择身份证！");
                }
                vo.setMotherIdcard(vo.getMotherIdcard().trim().toUpperCase());
            }
            if (ObjectUtils.isEmpty(vo.getMotherName())) {
                throw new AppException("母亲姓名不能为空！");
            } else {
                vo.setMotherName(
                        Validator.isChinese(vo.getMotherName())
                                ? vo.getMotherName().replace(" ", "").trim()
                                : vo.getMotherName().trim());
            }
            flag = false;
        }

        if (StringUtils.isNotBlank(vo.getFatherIdcard())) {
            boolean fatherFlag = IdcardUtil.isValidCard(vo.getFatherIdcard());
            if (CardTypeEnum.idcard.getType().equals(vo.getFatherCardType()) && !fatherFlag) {
                throw new AppException("父亲(监护人)身份证有误！");
            } else {
                if (fatherFlag && !CardTypeEnum.idcard.getType().equals(vo.getFatherCardType())) {
                    throw new AppException("父亲(监护人)证件类型，请选择身份证！");
                }
                vo.setFatherIdcard(vo.getFatherIdcard().trim().toUpperCase());
            }
            if (ObjectUtils.isEmpty(vo.getFatherName())) {
                throw new AppException("父亲(监护人)姓名不能为空！");
            } else {
                vo.setFatherName(
                        Validator.isChinese(vo.getFatherName())
                                ? vo.getFatherName().replace(" ", "").trim()
                                : vo.getFatherName().trim());
            }
            flag = false;
        }
        if (ObjectUtils.isEmpty(vo.getFullName())) {
            throw new AppException("学生姓名不能为空！");
        } else {
            vo.setFullName(
                    Validator.isChinese(vo.getFullName())
                            ? vo.getFullName().replace(" ", "").trim()
                            : vo.getFullName().trim());
        }
        if (flag) {
            throw new AppException("父亲（监护人）或母亲一方必填");
        }

        if (xsFlag) {
            if (StringUtils.isBlank(vo.getBirthYmd())) {
                vo.setBirthYmd(IdcardUtil.getBirth(vo.getIdcard()));
            }
            if (StringUtils.isBlank(vo.getSex())) {
                int gender = IdcardUtil.getGenderByIdCard(vo.getIdcard());
                if (gender == 1) {
                    // 男
                    vo.setSex("1");
                } else {
                    // 女
                    vo.setSex("2");
                }
            }
        }

    }

    public PageInfo<EduStudentEnrollVO> getEnrollLotteryList(EduStudentEnrollQueryVO vo) {
        if (StringUtils.isEmpty(vo.getConfigTypeName())) {
            throw new AppException("请先在查询类别中选择报名类别");
        }
        // 开启分页
        if (vo.getPageNum() != null && vo.getPageSize() != null) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        }
        List<EduStudentEnrollVO> list = eduStudentEnrollService.getEnrollLotteryList(vo);

        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentEnrollVO> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollVO> resultList = pageInfo.getList();

        for (EduStudentEnrollVO eduStudentEnrollVO : resultList) {
            eduStudentEnrollVO.setFullNameTm(getFullName(eduStudentEnrollVO.getFullName()));
            eduStudentEnrollVO.setIdcardTm(getIdcard(eduStudentEnrollVO.getIdcard()));
            eduStudentEnrollVO.setSexName(getSexName(eduStudentEnrollVO.getSex()));
            if ("1".equals(eduStudentEnrollVO.getBindMianFlag())) {
                QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().eq(EduStudentEnroll::getYear, vo.getYear())
                        .eq(EduStudentEnroll::getSchoolId, vo.getSchoolId())
                        .eq(EduStudentEnroll::getConfigTypeName, vo.getConfigTypeName())
                        .eq(EduStudentEnroll::getEnrollStatus, vo.getEnrollStatus())
                        .eq(EduStudentEnroll::getBindMianFlag, "0")
                        .eq(EduStudentEnroll::getBindIdcard, eduStudentEnrollVO.getIdcard());
                List<EduStudentEnroll> enrollList = eduStudentEnrollService.list(enrollQueryWrapper);
                if (!CollectionUtils.isEmpty(enrollList)) {
                    for (EduStudentEnroll enroll : enrollList) {
                        eduStudentEnrollVO.setApplyId(eduStudentEnrollVO.getApplyId() + "," + enroll.getApplyId());
                        eduStudentEnrollVO.setFullName(eduStudentEnrollVO.getFullName() + "," + enroll.getFullName());
                        eduStudentEnrollVO.setIdcard(eduStudentEnrollVO.getIdcard() + "," + enroll.getIdcard());
                        eduStudentEnrollVO.setFullNameTm(eduStudentEnrollVO.getFullNameTm()+","+getFullName(enroll.getFullName()));
                        eduStudentEnrollVO.setIdcardTm(eduStudentEnrollVO.getIdcardTm()+","+getIdcard(enroll.getIdcard()));
                        eduStudentEnrollVO.setSex(eduStudentEnrollVO.getSex() + "," + enroll.getSex());
                        eduStudentEnrollVO.setSexName(eduStudentEnrollVO.getSexName()+","+getSexName(enroll.getSex()));
                    }
                }
            }
        }

        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    private String getFullName(String str){
        if(StringUtils.isBlank(str)){
            return str;
        }
        if(str.length()<3){
            return str.substring(0,1)+"*";
        }else{
            int le=str.length()-1;
            return str.substring(0,1)+"*"+str.substring(le);
        }

    }

    //证件号码脱敏
    private String getIdcard(String str){
        if(StringUtils.isBlank(str)){
            return str;
        }
        if (str.length()==18) {
            return str.substring(0,6)+"********"+str.substring(14,18);
        }else{
            int len=str.length();
            String  enCard=str.substring(0, 2);
            for(int i=0;i<len-4;i++){
                enCard=enCard+"*";
            }
            enCard=enCard+str.substring(len-3);
            return enCard;
        }
    }

    private String getSexName(String str){
        if(StringUtils.isBlank(str)){
            return str;
        }
        if ("1".equals(str)) {
            return "男";
        } else if ("2".equals(str)){
            return "女";
        }else {
            return "未知";
        }
    }

    private void setPersonId(EduStudentEnroll enroll) {
        PersonInfo stuPersonInfo =
                this.savePerson(enroll.getIdcard(), enroll.getCardType(), enroll.getFullName());
        if (StringUtils.isNotBlank(enroll.getMotherIdcard())) {
            PersonInfo moPersonInfo =
                    this.savePerson(
                            enroll.getMotherIdcard(), enroll.getMotherCardType(), enroll.getMotherName());
        }
        if (StringUtils.isNotBlank(enroll.getFatherIdcard())) {
            PersonInfo faPersonInfo =
                    this.savePerson(
                            enroll.getFatherIdcard(), enroll.getFatherCardType(), enroll.getFatherName());
        }
    }

    private PersonInfo savePerson(String idcard, String cardType, String fullName) {
        if (StringUtils.isBlank(cardType)) {
            cardType = CardTypeEnum.idcard.getType();
        }
        if (!com.bifang.module.system.common.enums.CardTypeEnum.idcard.getType().equalsIgnoreCase(cardType)) {
            if (IdcardUtil.isValidCard(idcard)) {
                cardType = com.bifang.module.system.common.enums.CardTypeEnum.idcard.getType();
            }
        }
        PersonInfo personInfo = personInfoService.selectByCardTypeAndIdcard(cardType, StringUtils.upperCase(idcard));
        if (personInfo == null) {
            QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(PersonInfo::getIdcard, idcard);
            List<PersonInfo> list = personInfoService.list(queryWrapper);
            if (!CollectionUtils.isEmpty(list)) {
                personInfo = list.get(0);
            }
        }
        if (ObjectUtils.isEmpty(personInfo)) {
            personInfo = new PersonInfo();
            personInfo.setIdcard(StringUtils.upperCase(idcard));
            personInfo.setFullName(fullName);
            personInfo.setCardType(cardType);
            return personInfoService.addPerson(personInfo);
        } else {
            if (!personInfo.getFullName().equals(fullName) || !personInfo.getCardType().equals(cardType)) {
                personInfo.setFullName(fullName);
                personInfoService.updateById(personInfo);
            }
            return personInfo;
        }
    }

    private String getApplyId(Integer year, String schoolNature, String schoolNum, Integer orderNo, String shcoolId, Integer count) {
        if (count == null) {
            count = count + 1;
        }
        if (count > 10) {
            //超过10次未能比对到不重复的数据，返回报错
            throw new AppException("系统繁忙，请重新点提交");
        }
        String y = year % 100 + "";
        String num = StringUtils.leftPad(schoolNum, 9, "0");
        String orderNoId = StringUtils.leftPad(orderNo + "", 2, "0");
        String applyId = y + num + orderNoId;
        if ("0".equals(schoolNature)) {
            String redisKey = "ywEnroll:gb:" + shcoolId + ":" + orderNo;
            if (redisHelper.hasKey(redisKey)) {
                String redisApplyId = (String) redisHelper.get(redisKey);
                applyId = String.valueOf(Long.parseLong(redisApplyId) + 1);
                redisHelper.set(redisKey, applyId, 86400);
            } else {
                //公办
                String max = eduStudentEnrollService.queryMaxApplyId(applyId, shcoolId, year);
                if (StringUtils.isBlank(max)) {
                    applyId = applyId + StringUtils.leftPad("1", 4, "0");
                } else {
                    applyId = String.valueOf(Long.parseLong(max) + 1);
                }
                redisHelper.set(redisKey, applyId, 86400);
            }
            return applyId;
        } else {
            //民办或者公参民转公
            String redisKey = "ywEnroll:mb:" + shcoolId + ":" + orderNo;
            Integer randomId = null;
            if (redisHelper.hasKey(redisKey)) {

                List<Integer> randomList = (List<Integer>) redisHelper.get(redisKey);
                if (CollectionUtils.isEmpty(randomList)) {
                    Integer[] randomNums = NumberUtil.generateBySet(1, 9999, 3000);
                    randomList = Arrays.stream(randomNums).distinct().collect(Collectors.toList());
                    randomId = randomList.get(0);
                    randomList.remove(randomId);
                    redisHelper.set(redisKey, randomList, 259200);
                } else {
                    randomId = randomList.get(0);
                    randomList.remove(randomId);
                    redisHelper.set(redisKey, randomList, 259200);
                }

            } else {
                Integer[] randomNums = NumberUtil.generateBySet(1, 9999, 3000);
                List<Integer> randomList = Arrays.stream(randomNums).distinct().collect(Collectors.toList());
                randomId = randomList.get(0);
                randomList.remove(randomId);
                redisHelper.set(redisKey, randomList, 259200);
            }

            applyId = applyId + StringUtils.leftPad(randomId + "", 4, "0");

        }
        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(EduStudentEnroll::getStudentEnrollId).eq(EduStudentEnroll::getSchoolId, shcoolId)
                .eq(EduStudentEnroll::getYear, year)
                .eq(EduStudentEnroll::getApplyId, applyId);
        if (eduStudentEnrollService.count(queryWrapper) > 0) {
            applyId = this.getApplyId(year, schoolNature, schoolNum, orderNo, shcoolId, count);
        }
        return applyId;

    }

    //初审
    private void auth(StudentEnrollSaveVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAuthStatus())) {
            throw new AppException("审核状态不能为空");
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }


        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被回退，请重新查询");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.dlq.getType())) {
            throw new AppException("初审通过，不能重复审核");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType())) {
            throw new AppException("复审通过，不能进行初审");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.lq.getType())) {
            throw new AppException("已录取，不能进行初审");
        }
        int year;
        year = eduHelper.thisYear();

        if (old.getYear() < year) {
            throw new AppException("历年报名数据不允许审核");
        }


        //业务期判断
        EnrollCheckShLqVO checkShLqVO = new EnrollCheckShLqVO();
        checkShLqVO.setSchoolId(old.getSchoolId());
        checkShLqVO.setYear(old.getYear());
        checkShLqVO.setAreaCode(old.getAreaCode());
        if ("0".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType(old.getSchoolNature());
        }
        if ("1".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType("1");

        }
        checkShLqVO.setIsJyj(false);
        checkSh(checkShLqVO);

        if(!EnrollStatusFormalEnum.dsh.getType().equals(old.getEnrollStatus())&&!EnrollStatusFormalEnum.hy.getType().equals(old.getEnrollStatus())){
            throw new AppException(old.getFullName() + "的报名数据已审核，请重新查询");
        }

        if (!AuthStatusEnum.NODO.getType().equals(old.getAuthStatus())) {
            throw new AppException(old.getFullName() + "的报名数据已审核，请重新查询");
        }
        if (!old.getSchoolId().equals(SessionUtil.getSessionInfo().getOrgId())) {
            throw new AppException("报名学校和审核学校不一致，请联系管理员查找原因");
        }

        QueryWrapper<EduEnrollmenBrochure> queryBrochureWrapper = new QueryWrapper<>();
        queryBrochureWrapper.lambda().eq(EduEnrollmenBrochure::getYear, old.getYear())
                .eq(EduEnrollmenBrochure::getSchoolId, old.getSchoolId());
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(queryBrochureWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }

        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("招生已停止，不能审核");
        }

        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getStudentEnrollId)
                .eq(EduStudentEnroll::getIdcard, old.getIdcard())
                .eq(EduStudentEnroll::getYear, old.getYear())
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                .ne(EduStudentEnroll::getSchoolId, old.getSchoolId());
        if (eduStudentEnrollService.count(enrollQueryWrapper) > 0) {
            throw new AppException(old.getFullName() + "，其他学校资料审核通过或者已录取");
        }
        old.setAuthTime(new Date());
        old.setAuthRemarks(vo.getAuthRemarks());
        old.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
        if (AuthStatusEnum.NO.getType().equals(vo.getAuthStatus())) {
            //初审不通过
            //删除录取表，删除审核表 删除报名表
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("3");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("2");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("1");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
            old.setAdmitFlag(BoolEnum.FALSE.getType());
            if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
                old.setAuthRemarks(vo.getAuthRemarks());
            } else {
                old.setAuthRemarks("初审不通过");
            }

            old.setAdmitTime(old.getAuthTime());
            old.setAdmitUserId(SessionUtil.getSessionInfo().getUserId());
            old.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
            old.setAuthStatus(vo.getAuthStatus());
            old.setAuthTime(new Date());
            old.setAuthRemarks(vo.getAuthRemarks());
            old.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
        } else {
            //调用金华接口判断是否已录取
            EduSyncJhDeleteQueryVO syncJhDeleteQueryVO = new EduSyncJhDeleteQueryVO();
            syncJhDeleteQueryVO.setIdcard(old.getIdcard());
            syncJhDeleteQueryVO.setName(old.getFullName());
            syncJhDeleteQueryVO.setApplyCountyCode(old.getAreaCode());
            EduSyncExistInfo eduSyncExistInfo = syncJhDeleteIntegration.querySyncInfo(syncJhDeleteQueryVO);
            if (!ObjectUtils.isEmpty(eduSyncExistInfo)
                    && StringUtils.isNotBlank(eduSyncExistInfo.getType())
                    && eduSyncExistInfo.getType().equals("3")) {
                throw new AppException(eduSyncExistInfo.getName() + "在" + eduSyncExistInfo.getApplyEduName() + "已录取！");
            }

            old.setEnrollStatus(EnrollStatusFormalEnum.dlq.getType());
            if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
                old.setAuthRemarks(vo.getAuthRemarks());
            } else {
                old.setAuthRemarks("初审通过");
            }
            if (StringUtils.isNotBlank(vo.getAspirationType())) {
                old.setAspirationType(vo.getAspirationType());
            }
        }

        EduStudentEnrollReview eduStudentEnrollReview = new EduStudentEnrollReview();
        SessionInfo sessionInfo = SessionUtil.getSessionInfo();
        eduStudentEnrollReview.setStudentEnrollId(old.getStudentEnrollId());
        eduStudentEnrollReview.setAuditType(EnrollReviewStatusFormalEnum.cs.getType());
        eduStudentEnrollReview.setAuthUserId(sessionInfo.getUserId());
        eduStudentEnrollReview.setAuthUserName(sessionInfo.getUserName());
        eduStudentEnrollReview.setOrgId(sessionInfo.getOrgId());
        eduStudentEnrollReview.setOrgName(sessionInfo.getOrgName());
        eduStudentEnrollReview.setAuthStatus(vo.getAuthStatus());
        eduStudentEnrollReview.setAuthTime(new Date());
        if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
            eduStudentEnrollReview.setAuthRemarks(vo.getAuthRemarks());
        } else {
            if (AuthStatusEnum.YES.getType().equalsIgnoreCase(vo.getAuthStatus())) {
                eduStudentEnrollReview.setAuthRemarks("初审通过");
            } else {
                eduStudentEnrollReview.setAuthRemarks("初审不通过");
            }
        }
        eduStudentEnrollReviewService.save(eduStudentEnrollReview);
        eduStudentEnrollService.updateById(old);
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getMotherIdcard());
    }

    //复审
    private void review(StudentEnrollSaveVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAuthStatus())) {
            throw new AppException("审核状态不能为空");
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被回退，请重新查询");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.hy.getType())) {
            throw new AppException("未核验通过，不能进行复审");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.dsh.getType())) {
            throw new AppException("未初审通过，不能进行复审");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType())) {
            throw new AppException("学校复审通过，不能进行复审");
        }
        if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.lq.getType())) {
            throw new AppException("已被学校录取，不能进行复审");
        }
        int year;
        year = eduHelper.thisYear();

        if (old.getYear() < year) {
            throw new AppException("历年报名数据不允许审核");
        }


        //业务期判断
        EnrollCheckShLqVO checkShLqVO = new EnrollCheckShLqVO();
        checkShLqVO.setSchoolId(old.getSchoolId());
        checkShLqVO.setYear(old.getYear());
        checkShLqVO.setAreaCode(old.getAreaCode());
        if ("0".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType(old.getSchoolNature());
        }
        if ("1".equals(old.getSchoolNature())) {
            checkShLqVO.setOpType("1");
        }
        checkShLqVO.setIsJyj(true);
        checkSh(checkShLqVO);

        if (!AuthStatusEnum.NODO.getType().equals(old.getAuthStatus())) {
            throw new AppException(old.getFullName() + "的报名数据已审核，请重新查询");
        }


        QueryWrapper<EduEnrollmenBrochure> queryBrochureWrapper = new QueryWrapper<>();
        queryBrochureWrapper.lambda().eq(EduEnrollmenBrochure::getYear, old.getYear())
                .eq(EduEnrollmenBrochure::getSchoolId, old.getSchoolId());
        EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(queryBrochureWrapper, false);
        if (eduEnrollmenBrochure == null) {
            throw new AppException("未找到招生方案信息");
        }

        if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
            throw new AppException("招生已停止，不能审核");
        }

        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getStudentEnrollId)
                .eq(EduStudentEnroll::getIdcard, old.getIdcard())
                .eq(EduStudentEnroll::getYear, old.getYear())
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                .ne(EduStudentEnroll::getSchoolId, old.getSchoolId());
        if (eduStudentEnrollService.count(enrollQueryWrapper) > 0) {
            throw new AppException(old.getFullName() + "，其他学校资料审核通过或者已录取");
        }
        old.setAuthStatus(vo.getAuthStatus());
        old.setAuthTime(new Date());
        old.setAuthRemarks(vo.getAuthRemarks());
        old.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
        if (AuthStatusEnum.NO.getType().equals(vo.getAuthStatus())) {
            //复审不通过，删除录取表，删除审核表 删除报名表 同步数据
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("3");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("2");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("1");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }

            old.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());
            old.setAuthStatus(AuthStatusEnum.NO.getType());
            if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
                old.setAuthRemarks(vo.getAuthRemarks());
            } else {
                old.setAuthRemarks("复审不通过");
            }
            old.setAuthUserId(SessionUtil.getSessionInfo().getUserId());
            old.setAuthTime(new Date());
            old.setAdmitFlag(BoolEnum.FALSE.getType());
            old.setAdmitTime(old.getAuthTime());
            old.setAdmitUserId(SessionUtil.getSessionInfo().getUserId());
        } else {

            old.setEnrollStatus(EnrollStatusFormalEnum.fs.getType());
            if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
                old.setAuthRemarks(vo.getAuthRemarks());
            } else {
                old.setAuthRemarks("复审通过");
            }
            //调用金华接口判断是否已录取
            EduSyncJhDeleteQueryVO queryVO = new EduSyncJhDeleteQueryVO();
            queryVO.setIdcard(old.getIdcard());
            queryVO.setName(old.getFullName());
            queryVO.setApplyCountyCode(old.getAreaCode());
            EduSyncExistInfo eduSyncExistInfo = eduSyncJhDeleteService.querySyncInfo(queryVO);
            if (eduSyncExistInfo != null && "3".equals(eduSyncExistInfo.getType())) {
                //如果返回结果不为空并且是录取状态 判断行政区划是否为当前区县;
                if (!old.getAreaCode().equals(eduSyncExistInfo.getApplyCountyCode())) {
                    //如果不是当前区县，不能进行处理
                    throw new AppException("该学生以被" + eduSyncExistInfo.getApplyCountyName() + "教育局录取！");
                }
            }

            //复审通过
            // 1.同步报名数据
            EduSyncJhApplyVO applyVO = new EduSyncJhApplyVO();
            applyVO.setYear(old.getYear());
            applyVO.setSchoolCategory(old.getSchoolCategory());
            ;
            applyVO.setCardType(old.getCardType());
            applyVO.setName(old.getFullName());
            applyVO.setIdcard(old.getIdcard());
            applyVO.setSex(old.getSex());
            applyVO.setHouseholdAddress(old.getHouseholdPlace());
            applyVO.setResidentialAddress(old.getAddress());
            if (StringUtils.isNotBlank(old.getFatherIdcard())) {
                applyVO.setMasterGuardianNumber(old.getFatherIdcard());
                applyVO.setMasterGuardianName(old.getFatherName());
                applyVO.setMasterGuardianRelation("1");
            }
            if (StringUtils.isNotBlank(old.getMotherIdcard())) {
                applyVO.setSlaveGuardianNumber(old.getMotherIdcard());
                applyVO.setSlaveGuardianName(old.getMotherName());
                applyVO.setSlaveGuardianRelation("2");
            }
            applyVO.setApplyCountyCode(old.getAreaCode());
            //当前时间戳
            applyVO.setApplyTime(System.currentTimeMillis());
            if (!applyVO.getCardType().equals(CardTypeEnum.idcard)) {
                if (applyVO.getSex().equals("1")) {
                    applyVO.setSex("0");
                } else if (applyVO.getSex().equals("2")) {
                    applyVO.setSex("1");
                }
            }
            try {
                applyIntegration.saveSyncApplyInfo2(applyVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }

            //2.同步审核表数据
            EduSyncJhApproveVO syncJhApproveVO = new EduSyncJhApproveVO();
            syncJhApproveVO.setSchoolCategory(old.getSchoolCategory());
            syncJhApproveVO.setApproveState(AuthStatusEnum.YES.getType());
            syncJhApproveVO.setApproveTime(new Date());
            syncJhApproveVO.setApproveHuman(SessionUtil.getUserId());
            syncJhApproveVO.setCardType(old.getCardType());
            syncJhApproveVO.setName(old.getFullName());
            syncJhApproveVO.setIdcard(old.getIdcard());
            syncJhApproveVO.setApplyCountyCode(old.getAreaCode());
            syncJhApproveVO.setApproveOpinion(old.getAuthRemarks());
            try {
                approveIntegration.saveSyncApproveInfo2(syncJhApproveVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        }
        LambdaQueryWrapper<EduStudentEnrollVerification> queryWrapper = new QueryWrapper<EduStudentEnrollVerification>().lambda().eq(EduStudentEnrollVerification::getStudentEnrollId, old.getStudentEnrollId());
        List<EduStudentEnrollVerification> verificationList = eduStudentEnrollVerificationService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(verificationList) && !old.getIcertificatioFlag().equals("0")) {
            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
            List<EduStudentEnrollVerificationVO> verificationVOList = Convert.toList(EduStudentEnrollVerificationVO.class, verificationList);
            for (EduStudentEnrollVerificationVO ver : verificationVOList) {
                if (StringUtils.isNotBlank(vo.getIcertificatioFlag())) {
                    if (vo.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hytg.getType())) {
                        ver.setVerificationStatus("1");
                    } else if (vo.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hybtg.getType())) {
                        ver.setVerificationStatus("2");
                    }
                }
            }
            verificationVO.setVerificationVOList(verificationVOList);
            verificationVO.setStudentEnrollId(old.getStudentEnrollId());
            if (StringUtils.isNotBlank(vo.getIcertificatioFlag())) {
                verificationVO.setIcertificatioFlag(vo.getIcertificatioFlag());
            }
            this.reviewVerificationAudit(verificationVO);
            //更新线下审核状态
            if (StringUtils.isNotBlank(vo.getIcertificatioFlag())) {
                old.setIcertificatioFlag(vo.getIcertificatioFlag());
            }
            if (old.getEnrollStatus().equals(EnrollStatusFormalEnum.fs.getType()) && !old.getIcertificatioFlag().equals(VerificationAuthStatusEnum.hytg.getType())) {
                throw new AppException("核验材料不通过，不能复审通过！");
            }
        }
        EduStudentEnrollReview eduStudentEnrollReview = new EduStudentEnrollReview();
        SessionInfo sessionInfo = SessionUtil.getSessionInfo();
        eduStudentEnrollReview.setStudentEnrollId(old.getStudentEnrollId());
        eduStudentEnrollReview.setAuditType(EnrollReviewStatusFormalEnum.fs.getType());
        eduStudentEnrollReview.setAuthUserId(sessionInfo.getUserId());
        eduStudentEnrollReview.setAuthUserName(sessionInfo.getUserName());
        eduStudentEnrollReview.setOrgId(sessionInfo.getOrgId());
        eduStudentEnrollReview.setOrgName(sessionInfo.getOrgName());
        eduStudentEnrollReview.setAuthStatus(vo.getAuthStatus());
        eduStudentEnrollReview.setAuthTime(new Date());
        if (StringUtils.isNotBlank(vo.getAuthRemarks())) {
            eduStudentEnrollReview.setAuthRemarks(vo.getAuthRemarks());
        } else {
            if (AuthStatusEnum.YES.getType().equalsIgnoreCase(vo.getAuthStatus())) {
                eduStudentEnrollReview.setAuthRemarks("复审通过");
            } else {
                eduStudentEnrollReview.setAuthRemarks("复审不通过");
            }
        }
        eduStudentEnrollReviewService.save(eduStudentEnrollReview);
        eduStudentEnrollService.updateById(old);
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getMotherIdcard());
    }

    public void reviewVerificationAudit(EduStudentEnrollVerificationVO vo) {
        Integer year = eduHelper.thisYear();
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被回退，请重新查询");
        }
        if (old.getYear() < year) {
            throw new AppException("历年报名数据不允许核验");
        }

        if (!CollectionUtils.isEmpty(vo.getVerificationVOList())) {
            ArrayList<EduStudentEnrollVerification> list = new ArrayList<>();
            UpdateWrapper<EduStudentEnrollPre> preUpdateWrapper = new UpdateWrapper<>();
            preUpdateWrapper.lambda().eq(EduStudentEnrollPre::getIdcard, old.getIdcard())
                    .eq(EduStudentEnrollPre::getYear, old.getYear());
            boolean updateFlag = false;
            for (EduStudentEnrollVerificationVO ver : vo.getVerificationVOList()) {
                ver.setVerificationUserId(SessionUtil.getUserId());
                ver.setVerificationTime(new Date());
                EduStudentEnrollVerification verification = Convert.convert(EduStudentEnrollVerification.class, ver);
                list.add(verification);
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(ver.getVerificationStatus())) {
                    //核验通过
                    if (VerificationTypeEnum.yzb.getType().equalsIgnoreCase(ver.getVerificationType())
                            || VerificationTypeEnum.fwq.getType().equalsIgnoreCase(ver.getVerificationType())
                            || VerificationTypeEnum.fhyz.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getHouseId, old.getHouseId())
                                .set(EduStudentEnrollPre::getHouseholdId, old.getHouseholdId())
                                .set(EduStudentEnrollPre::getConsistentType, "2")//人工核对
                                .set(EduStudentEnrollPre::getConsistentFlag, BoolEnum.TRUE.getType())
                                .set(EduStudentEnrollPre::getConsistentRemarks, "报名后线下人工核验")
                                .set(EduStudentEnrollPre::getConsistentTime, new Date())
                                .set(EduStudentEnrollPre::getConsistentUserId, SessionUtil.getUserId());
                        updateFlag = true;
                    }
                    if (VerificationTypeEnum.yzb.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getAborigineFlag, BoolEnum.TRUE.getType());
                    }
                    if (VerificationTypeEnum.fwq.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getServiceAreaFlag, BoolEnum.TRUE.getType());
                    }
                    if (VerificationTypeEnum.qzgx.getType().equalsIgnoreCase(ver.getVerificationType())) {
                        preUpdateWrapper.lambda().set(EduStudentEnrollPre::getFamilyFlag, BoolEnum.TRUE.getType())
                                .set(EduStudentEnrollPre::getFamilyType, "2")
                                .set(EduStudentEnrollPre::getFamilyRemark, "报名后线下人工核验");
                        updateFlag = true;
                    }
                }
            }
            if (updateFlag) {
                eduStudentEnrollPreService.update(preUpdateWrapper);
            }
            //更新校验表
            eduStudentEnrollVerificationService.updateBatchById(list);
        }
    }

    @Override
    public void checkSh(EnrollCheckShLqVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("年度不能为空");
        }
        if (StringUtils.isBlank(vo.getOpType())) {
            throw new AppException("操作类型不能为空");
        }


        int year = eduHelper.thisYear();

        if (vo.getYear() < year) {
            throw new AppException("招生审核工作已结束，不能审核");
        } else if (vo.getYear() > year) {
            throw new AppException("招生审核工作尚未开始，不能审核");
        }
        // EduEnrollPlan eduEnrollPlan = enrollPlanIntegration.getByYear(year);
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduOperationCacheQueryVO cacheQueryVO = Convert.convert(EduOperationCacheQueryVO.class, vo);
        cacheQueryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(cacheQueryVO);
        if (eduOperationCacheVO.getOperation() == null) {
            throw new AppException(year + "年度招生计划参数不存在");
        }
        Long current = DateUtil.currentSeconds();
        if (!vo.getIsJyj()){
            //authPower=true当前学段处于报名中不能审核
            Boolean authPower = primaryAndJuniorAuthPower(Convert.convert(EduStudentEnrollPreKeyVO.class, vo));
            if (authPower) {
                throw new AppException("当前学段处于报名中不能审核");
            }
        }
        if ("0".equals(vo.getOpType())) {
            //公办
            if (eduOperationCacheVO.getOperation().get("YW003") == null) {
                throw new AppException("招生审核工作尚未开始，不能审核");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW003").isFlag()) {
                    if ("1".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW003").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW003").getMessagePrompts());
                    } else if ("2".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW003").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW003").getMessageTip());
                    } else {
                        throw new AppException("招生审核工作尚未开始，不能审核");
                    }
                }
            }

        } else if ("1".equals(vo.getOpType())) {
            //民办1
            if (eduOperationCacheVO.getOperation().get("YW007") == null) {
                throw new AppException("招生审核工作尚未开始，不能审核");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW007").isFlag()) {
                    if ("1".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW007").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW007").getMessagePrompts());
                    } else if ("2".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW007").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW007").getMessageTip());
                    } else {
                        throw new AppException("招生审核工作尚未开始，不能审核");
                    }
                }
            }
        } else if ("2".equals(vo.getOpType())) {
            //民转公
            if (eduOperationCacheVO.getOperation().get("YW014") == null) {
                throw new AppException("招生审核工作尚未开始，不能审核");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW014").isFlag()) {
                    if ("1".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW014").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW014").getMessagePrompts());
                    } else if ("2".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW014").getType())) {
                        throw new AppException(eduOperationCacheVO.getOperation().get("YW014").getMessageTip());
                    } else {
                        throw new AppException("招生审核工作尚未开始，不能审核");
                    }

                }
            }
        } else if ("3".equals(vo.getOpType())) {
            //民办2
            if (eduOperationCacheVO.getOperation().get("YW011") == null) {
                throw new AppException("招生审核工作尚未开始，不能审核");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW011").isFlag()) {
                    if (!eduOperationCacheVO.getOperation().get("YW011").isFlag()) {
                        if ("1".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW011").getType())) {
                            throw new AppException(eduOperationCacheVO.getOperation().get("YW011").getMessagePrompts());
                        } else if ("2".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW011").getType())) {
                            throw new AppException(eduOperationCacheVO.getOperation().get("YW011").getMessageTip());
                        } else {
                            throw new AppException("招生审核工作尚未开始，不能审核");
                        }

                    }
                }
            }
        } else if ("4".equals(vo.getOpType())) {
            //民办3
            if (eduOperationCacheVO.getOperation().get("YW055") == null) {
                throw new AppException("招生审核工作尚未开始，不能审核");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW055").isFlag()) {
                    if (!eduOperationCacheVO.getOperation().get("YW055").isFlag()) {
                        if ("1".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW055").getType())) {
                            throw new AppException(eduOperationCacheVO.getOperation().get("YW055").getMessagePrompts());
                        } else if ("2".equalsIgnoreCase(eduOperationCacheVO.getOperation().get("YW055").getType())) {
                            throw new AppException(eduOperationCacheVO.getOperation().get("YW055").getMessageTip());
                        } else {
                            throw new AppException("招生审核工作尚未开始，不能审核");
                        }

                    }
                }
            }
        }
    }

    @Override
    public void checklq(EnrollCheckShLqVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("年度不能为空");
        }
        if (StringUtils.isBlank(vo.getOpType())) {
            throw new AppException("操作类型不能为空");
        }


        int year = eduHelper.thisYear();


        if (vo.getYear() < year) {
            throw new AppException("招生录取工作已结束，不能录取");
        } else if (vo.getYear() > year) {
            throw new AppException("招生录取工作尚未开始，不能录取");
        }
        // EduEnrollPlan eduEnrollPlan = enrollPlanIntegration.getByYear(year);
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        EduOperationCacheQueryVO cacheQueryVO = Convert.convert(EduOperationCacheQueryVO.class, vo);
        cacheQueryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(cacheQueryVO);
        if (eduOperationCacheVO.getOperation() == null) {
            throw new AppException(year + "年度招生计划参数不存在");
        }
        Long current = DateUtil.currentSeconds();
        if ("0".equals(vo.getOpType())) {
            if (eduOperationCacheVO.getOperation().get("YW004") == null) {
                throw new AppException("招生录取工作尚未开始，不能录取");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW004").isFlag()) {
                    throw new AppException("招生录取工作尚未开始或已结束，不能录取");
                }
            }

        } else if ("1".equals(vo.getOpType())) {
            //民办1
            if (eduOperationCacheVO.getOperation().get("YW009") == null) {
                throw new AppException("招生录取工作尚未开始，不能录取");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW009").isFlag()) {
                    throw new AppException("招生录取工作尚未开始，不能录取");
                }
            }
        } else if ("2".equals(vo.getOpType())) {
            //民转公
            if (eduOperationCacheVO.getOperation().get("YW016") == null) {
                throw new AppException("招生录取工作尚未开始，不能录取");
            } else {
                if (!eduOperationCacheVO.getOperation().get("YW016").isFlag()) {
                    throw new AppException("招生录取工作尚未开始，不能录取");
                }
            }
        }
    }

    private StudentEnrollLqVO admit(StudentEnrollSaveVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (StringUtils.isBlank(vo.getAdmitFlag())) {
            throw new AppException("录取状态不能为空");
        }

        EduStudentEnroll old = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (old == null) {
            throw new AppException("报名数据不存在，可能已被回退，请重新查询");
        }
        //业务期判断
        EnrollCheckShLqVO checkShLqVO = new EnrollCheckShLqVO();
        checkShLqVO.setSchoolId(old.getSchoolId());
        checkShLqVO.setYear(old.getYear());
        checkShLqVO.setAreaCode(old.getAreaCode());
        checkShLqVO.setOpType(old.getSchoolNature());
        checklq(checkShLqVO);
        if (StringUtils.isNotBlank(old.getAdmitFlag())) {
            throw new AppException(old.getFullName() + "的报名数据已操作，请重新查询");
        }
        if (!AuthStatusEnum.YES.getType().equals(old.getAuthStatus())) {
            throw new AppException(old.getFullName() + "的报名数据未审核通过，不能录取");
        }
        if (!old.getSchoolId().equals(SessionUtil.getSessionInfo().getOrgId())) {
            throw new AppException("报名学校和录取学校不一致，请联系管理员查找原因");
        }
//        QueryWrapper<EduStudentEnroll> dshQuery = new QueryWrapper<>();
//        dshQuery.lambda().eq(EduStudentEnroll::getYear, old.getYear())
//                .eq(EduStudentEnroll::getSchoolId, old.getSchoolId())
//                .eq(!"0".equals(old.getSchoolNature()), EduStudentEnroll::getConfigTypeName, old.getConfigTypeName())
//                .eq("0".equals(old.getSchoolNature()), EduStudentEnroll::getConfigName, old.getConfigName())
//                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType())
//                .eq("1".equals(old.getSchoolNature()), EduStudentEnroll::getAspirationType, old.getAspirationType());
//        if (eduStudentEnrollService.count(dshQuery) > 0) {
//            throw new AppException("同一报名类别存在待审核数据，请全部审核后再录取");
//        }

        //超过计划数不能录取
        QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                .eq(EduSchoolConfig::getSchoolId, old.getSchoolId())
                .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                .eq(EduSchoolConfig::getYear, old.getYear());
        if ("1".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
            brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, old.getYear())
                    .eq(EduEnrollmenBrochure::getSchoolId, old.getSchoolId());
            EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
            if (eduEnrollmenBrochure == null) {
                throw new AppException("未找到招生方案信息");
            }

            if (BoolEnum.TRUE.getType().equals(eduEnrollmenBrochure.getEndRegistration())) {
                throw new AppException("招生已停止，不能录取");
            }


            //民办
            configQueryWrapper.lambda().eq(EduSchoolConfig::getConfigTypeName, old.getConfigTypeName());
        }
        EduSchoolConfig eduSchoolConfig = eduSchoolConfigService.getOne(configQueryWrapper, false);
        StudentEnrollLqVO retVO = new StudentEnrollLqVO();
        //计划人数 如果没有计划信息，不控制录入人数
        Integer enrolment = 0;
        if (eduSchoolConfig != null) {
            enrolment = eduSchoolConfig.getEnrolment() == null ? 1000 : eduSchoolConfig.getEnrolment();
        } else {
            enrolment = 1000;
        }
        //摇号截止序号
        Integer serialNumEnd = 0;
        if (eduSchoolConfig != null) {
            serialNumEnd = eduSchoolConfig.getSerialNumEnd() == null ? 0 : eduSchoolConfig.getSerialNumEnd();
        }
        //已录取人数
        QueryWrapper<EduStudentEnroll> lqQuery = new QueryWrapper<>();
        lqQuery.lambda().eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                .eq(EduStudentEnroll::getYear, old.getYear())
                .eq(EduStudentEnroll::getAdmitFlag, BoolEnum.TRUE.getType())
                .eq(EduStudentEnroll::getSchoolId, old.getSchoolId());
        if ("1".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            //民办
            lqQuery.lambda().eq(EduStudentEnroll::getConfigTypeName, old.getConfigTypeName());
        }
        long lqCount = eduStudentEnrollService.count(lqQuery);
        if (lqCount >= enrolment) {
            throw new AppException("录取人数已到达计划人数，如还需录取，请联系基教科修改招生计划");
        }
        if ("1".equals(old.getSchoolNature()) || "2".equals(old.getSchoolNature())) {
            //民办或民转公
            if (old.getSerialNum() != null) {
                QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda().eq(EduStudentEnroll::getSchoolId, old.getSchoolId())
                        .lt(EduStudentEnroll::getSerialNum, old.getSerialNum())
                        .eq(EduStudentEnroll::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType())
                        .eq(EduStudentEnroll::getConfigTypeName, old.getConfigTypeName())
                        .eq("1".equals(old.getSchoolNature()), EduStudentEnroll::getAspirationType, old.getAspirationType());
                if (eduStudentEnrollService.count(queryWrapper) > 0) {
                    throw new AppException("请按摇号排序号顺序录取");
                }
                if (eduSchoolConfig == null || eduSchoolConfig.getSerialNumEnd() == null) {
                    throw new AppException("请先联系系统管理员配置录取的摇号排序号截止序号");
                }
                //判断摇号序号是否全部导入
                if (old.getSerialNum() > eduSchoolConfig.getSerialNumEnd()) {
                    throw new AppException("该摇号人员已超出可录取的范围");
                }
                old.setAdmitFlag(BoolEnum.TRUE.getType());
                if (StringUtils.isBlank(old.getAdmitRemarks())) {
                    old.setAdmitRemarks("摇号录取");
                }
            }
        } else {
            //公办 需要按排序号，排序号高的优先录取 特殊通道不校验
            EduSchool eduSchool = eduSchoolService.getById(old.getSchoolId());
            if (eduSchool == null) {
                throw new AppException("学校基础信息不存在，请联系系统管理员");
            }
            if (!BoolEnum.TRUE.getType().equals(eduSchool.getAuthOrderByNo())) {
                if (!BoolEnum.TRUE.getType().equals(old.getSpecialFlag())) {
                    QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
                    queryWrapper.lambda().eq(EduStudentEnroll::getYear, old.getYear())
                            .eq(EduStudentEnroll::getSchoolId, old.getSchoolId())
                            .lt(EduStudentEnroll::getConfigName, old.getConfigName())
                            .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.dlq.getType());
                    if (eduStudentEnrollService.count(queryWrapper) > enrolment) {
                        throw new AppException("请按报名类别的排序号的顺序录取，比如A类全部录取完才能录取B类");
                    }
                }
            }

        }
        retVO.setJhCnt(enrolment);
        retVO.setLqCnt((int) lqCount);
        old.setAdmitFlag(vo.getAdmitFlag());
        old.setAdmitRemarks(vo.getAdmitRemarks());
        old.setAdmitTime(new Date());
        old.setAdmitUserId(SessionUtil.getSessionInfo().getUserId());
        if (BoolEnum.TRUE.getType().equals(vo.getAdmitFlag())) {
            // 金华全市录取查询
            //需要调用查询接口，判断其他区县是否有录取数据
            EduSyncJhDeleteQueryVO queryVO = new EduSyncJhDeleteQueryVO();
            queryVO.setIdcard(old.getIdcard());
            queryVO.setName(old.getFullName());
            queryVO.setApplyCountyCode(old.getAreaCode());
            EduSyncExistInfo eduSyncExistInfo = eduSyncJhDeleteService.querySyncInfo(queryVO);
            if (eduSyncExistInfo != null && "3".equals(eduSyncExistInfo.getType())) {
                //如果返回结果不为空并且是录取状态 判断行政区划是否为当前区县;
                if (!old.getAreaCode().equals(eduSyncExistInfo.getApplyCountyCode())) {
                    //如果不是当前区县，不能进行处理
                    throw new AppException("该学生以被" + eduSyncExistInfo.getApplyCountyName() + "教育局录取！");
                }
            }

            List<String> enrollStatusList = new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
            QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().select(EduStudentEnroll::getStudentEnrollId)
                    .eq(EduStudentEnroll::getParentId, old.getStudentEnrollId())
                    .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                    .ne(EduStudentEnroll::getSchoolId, old.getSchoolId());
            if (eduStudentEnrollService.count(queryWrapper) > 0) {
                throw new AppException(old.getFullName() + "，金华市区内其他学校待录取或者已录取");
            }

            old.setEnrollStatus(EnrollStatusFormalEnum.lq.getType());

            //同步报名表，审核表，录取表
            //复审通过
            // 1.同步报名数据
            EduSyncJhApplyVO applyVO = new EduSyncJhApplyVO();
            applyVO.setYear(old.getYear());
            applyVO.setSchoolCategory(old.getSchoolCategory());
            ;
            applyVO.setCardType(old.getCardType());
            applyVO.setName(old.getFullName());
            applyVO.setIdcard(old.getIdcard());
            applyVO.setSex(old.getSex());
            applyVO.setHouseholdAddress(old.getHouseholdPlace());
            applyVO.setResidentialAddress(old.getAddress());
            if (StringUtils.isNotBlank(old.getFatherIdcard())) {
                applyVO.setMasterGuardianNumber(old.getFatherIdcard());
                applyVO.setMasterGuardianName(old.getFatherName());
                applyVO.setMasterGuardianRelation("1");
            }
            if (StringUtils.isNotBlank(old.getMotherIdcard())) {
                applyVO.setSlaveGuardianNumber(old.getMotherIdcard());
                applyVO.setSlaveGuardianName(old.getMotherName());
                applyVO.setSlaveGuardianRelation("2");
            }
            applyVO.setApplyCountyCode(old.getAreaCode());
            //当前时间戳
            applyVO.setApplyTime(System.currentTimeMillis());
            if (!applyVO.getCardType().equals(CardTypeEnum.idcard)) {
                if (applyVO.getSex().equals("1")) {
                    applyVO.setSex("0");
                } else if (applyVO.getSex().equals("2")) {
                    applyVO.setSex("1");
                }
            }
            try {
                applyIntegration.saveSyncApplyInfo2(applyVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }

            //2.同步审核表数据
            EduSyncJhApproveVO syncJhApproveVO = new EduSyncJhApproveVO();
            syncJhApproveVO.setSchoolCategory(old.getSchoolCategory());
            syncJhApproveVO.setApproveState(AuthStatusEnum.YES.getType());
            syncJhApproveVO.setApproveTime(new Date());
            syncJhApproveVO.setApproveHuman(SessionUtil.getUserId());
            syncJhApproveVO.setCardType(old.getCardType());
            syncJhApproveVO.setName(old.getFullName());
            syncJhApproveVO.setIdcard(old.getIdcard());
            syncJhApproveVO.setApplyCountyCode(old.getAreaCode());
            syncJhApproveVO.setApproveOpinion(old.getAuthRemarks());
            try {
                approveIntegration.saveSyncApproveInfo2(syncJhApproveVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }

            //3.同步录取表数据
            EduSyncJhEnrollVO syncJhEnrollVO = new EduSyncJhEnrollVO();
            syncJhEnrollVO.setSchoolCategory(old.getSchoolCategory());
            syncJhEnrollVO.setCardType(old.getCardType());
            syncJhEnrollVO.setName(old.getFullName());
            syncJhEnrollVO.setIdcard(old.getIdcard());
            syncJhEnrollVO.setEnrollState(AuthStatusEnum.YES.getType());
            syncJhEnrollVO.setEnrollHuman(SessionUtil.getUserId());
            syncJhEnrollVO.setEnrollTime(new Date());
            syncJhEnrollVO.setEnrollSchoolName(old.getSchoolName());
            syncJhEnrollVO.setEnrollSchoolCode(old.getSchoolId());
            syncJhEnrollVO.setApplyCountyCode(old.getAreaCode());
            syncJhEnrollVO.setEnrollOpinion(old.getAuthRemarks());
            enrollIntegration.saveSyncEnrollInfo2(syncJhEnrollVO);
        } else {
            old.setEnrollStatus(EnrollStatusFormalEnum.ywblq.getType());

            //不录取，删除录取表，删除审核表 删除报名表 同步数据
            EduSyncJhDeleteQueryVO deleteQueryVO = new EduSyncJhDeleteQueryVO();
            deleteQueryVO.setIdcard(old.getIdcard());
            deleteQueryVO.setApplyCountyCode(old.getAreaCode());
            try {
                deleteQueryVO.setDeleteType("3");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("2");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
                deleteQueryVO.setDeleteType("1");
                syncJhDeleteIntegration.syncJhDeleteByType2(deleteQueryVO);
            } catch (AppException e) {
                throw new AppException(e.getMessage());
            } catch (Exception e) {
                throw new AppException(e.getMessage());
            }
        }
        //添加已录取的学生家长身份证手机号到短信发送表
        ArrayList<EduSendMessageVO> messageVOS = new ArrayList<>();
        if (StringUtils.isNotBlank(old.getFatherIdcard())){
            EduSendMessageVO sendMessageVO = new EduSendMessageVO();
            sendMessageVO.setParentName(old.getFatherName());
            sendMessageVO.setParentPhone(old.getFatherCellphone());
            messageVOS.add(sendMessageVO);
        }
        if (StringUtils.isNotBlank(old.getMotherIdcard())){
            EduSendMessageVO sendMessageVO = new EduSendMessageVO();
            sendMessageVO.setParentName(old.getMotherName());
            sendMessageVO.setParentPhone(old.getMotherCellphone());
            messageVOS.add(sendMessageVO);
        }
        for (EduSendMessageVO sendMessage:messageVOS) {
            sendMessage.setMessageId(IdUtil.simpleUUID());
            sendMessage.setYear(old.getYear());
            sendMessage.setEnrollNum(old.getEnrollNum());
            sendMessage.setStudentEnrollId(old.getStudentEnrollId());
            sendMessage.setSendStatus(SendStatusEnum.cg.getType());
            sendMessage.setAreaCode(old.getAreaCode());
            sendMessage.setStudentIdcard(old.getIdcard());
            sendMessage.setPushStatus("0");
            eduSendMessageService.save(Convert.convert(EduSendMessage.class,sendMessage));
        }
        //同步到计划录取表
        eduStudentEnrollService.updateById(old);
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(old.getMotherIdcard());
        return retVO;
    }

}
